Set lattice on open

This commit is contained in:
2022-09-23 14:22:44 -04:00
parent 267c5e5c5c
commit 5d40050580
2 changed files with 22 additions and 4 deletions

View File

@ -51,12 +51,29 @@ class Painter(Widget):
self.keyboard = Window.request_keyboard(None,self,"text")
self.keyboard.bind(on_key_down=self.on_key_down,on_key_up=self.on_key_up,on_textinput=self.on_textinput)
# redraw on resize
self.bind(size=lambda obj,value: self.draw())
def reset(self):
self.particles=[]
self.undermouse=None
self.draw()
# set lattice
def set_lattice(self,lattice):
self.lattice=lattice
# draw
self.draw()
# snap all existing particles to grid
for particle in self.particles:
delta=self.lattice.nearest_delta(particle.squares[0].pos)
if not self.check_interaction_any(particle,delta):
particle.move(delta)
# convert logical coordinates (normalized and centered) to the ones that are plotted
def pos_tocoord_x(self,x):
return self.width/2+x*Square_element.size