Split element into their own file
This commit is contained in:
@ -6,7 +6,6 @@ from kivy.graphics import Color,Line
|
||||
|
||||
from point import Point
|
||||
from polyomino import Cross
|
||||
from polyomino import Square_element
|
||||
|
||||
from tools import remove_fromlist
|
||||
|
||||
@ -71,7 +70,7 @@ class Painter(Widget):
|
||||
|
||||
# snap all existing particles to grid
|
||||
for particle in self.particles:
|
||||
delta=self.lattice.nearest_delta(particle.squares[0].pos)
|
||||
delta=self.lattice.nearest_delta(particle.elements[0].pos)
|
||||
if not self.check_interaction_any(particle,delta):
|
||||
particle.move(delta)
|
||||
|
||||
@ -104,7 +103,7 @@ class Painter(Widget):
|
||||
# draw grids
|
||||
for particle in self.particles:
|
||||
if particle.grid>0:
|
||||
self.draw_grid(particle.squares[0].pos,particle.grid)
|
||||
self.draw_grid(particle.elements[0].pos,particle.grid)
|
||||
|
||||
for particle in self.particles:
|
||||
particle.draw(self,alpha=0.5)
|
||||
@ -217,7 +216,7 @@ class Painter(Widget):
|
||||
new=Cross(touchx,touchy)
|
||||
# snap to lattice
|
||||
if self.lattice!=None:
|
||||
new.move(self.lattice.nearest_delta(new.squares[0].pos))
|
||||
new.move(self.lattice.nearest_delta(new.elements[0].pos))
|
||||
|
||||
if not self.check_interaction_any(new,Point(0,0)):
|
||||
# add to list
|
||||
@ -238,7 +237,7 @@ class Painter(Widget):
|
||||
|
||||
# record relative position of click with respect to reference
|
||||
if self.undermouse!=None:
|
||||
self.offset=Point(touchx,touchy)-self.undermouse.squares[0].pos
|
||||
self.offset=Point(touchx,touchy)-self.undermouse.elements[0].pos
|
||||
|
||||
# no modifiers
|
||||
if self.modifiers==[]:
|
||||
@ -291,7 +290,7 @@ class Painter(Widget):
|
||||
# only move on left click
|
||||
if touch.button=="left" and self.modifiers==[] and self.undermouse!=None:
|
||||
# attempted move determined by the relative position to the relative position of click within self.undermouse
|
||||
delta=self.adjust_move(Point(touchx,touchy)-(self.offset+self.undermouse.squares[0].pos),0)
|
||||
delta=self.adjust_move(Point(touchx,touchy)-(self.offset+self.undermouse.elements[0].pos),0)
|
||||
|
||||
# snap to lattice
|
||||
if self.lattice!=None:
|
||||
@ -347,10 +346,10 @@ class Painter(Widget):
|
||||
# check whether a candidate particle element with any of the unselected particles
|
||||
def check_interaction_unselected_element(self,element,offset):
|
||||
for particle in self.unselected:
|
||||
for square in particle.squares:
|
||||
for elt in particle.elements:
|
||||
# add offset
|
||||
element.pos+=offset
|
||||
if square.check_interaction(element):
|
||||
if elt.check_interaction(element):
|
||||
# reset offset
|
||||
element.pos-=offset
|
||||
return True
|
||||
@ -365,7 +364,7 @@ class Painter(Widget):
|
||||
# actual_delta is the smallest (componentwise) of all the computed delta's
|
||||
actual_delta=Point(math.inf,math.inf)
|
||||
for particle in self.selected:
|
||||
for element in particle.squares:
|
||||
for element in particle.elements:
|
||||
# compute adjustment move due to unselected obstacles
|
||||
adjusted_delta=self.adjust_move_element(delta,element,0)
|
||||
# only keep the smallest delta's (in absolute value)
|
||||
@ -391,7 +390,7 @@ class Painter(Widget):
|
||||
# whether newpos is acceptable
|
||||
accept_newpos=True
|
||||
for other in self.unselected:
|
||||
for obstacle in other.squares:
|
||||
for obstacle in other.elements:
|
||||
# move would make element overlap with obstacle
|
||||
element.pos+=delta
|
||||
if obstacle.check_interaction(element):
|
||||
@ -448,7 +447,7 @@ class Painter(Widget):
|
||||
for particle in self.particles:
|
||||
if type(particle)==Cross:
|
||||
ff.write("{:d};".format(CROSS_INDEX))
|
||||
ff.write("{:05.2f},{:05.2f};{:3.1f},{:3.1f},{:3.1f}\n".format(particle.squares[0].pos.x,particle.squares[0].pos.y,particle.color[0],particle.color[1],particle.color[2]))
|
||||
ff.write("{:05.2f},{:05.2f};{:3.1f},{:3.1f},{:3.1f}\n".format(particle.elements[0].pos.x,particle.elements[0].pos.y,particle.color[0],particle.color[1],particle.color[2]))
|
||||
ff.close()
|
||||
|
||||
# read configuration from file
|
||||
@ -561,7 +560,7 @@ class Painter(Widget):
|
||||
for particle in self.particles:
|
||||
if type(particle)==Cross:
|
||||
ff.write("\cross{"+colors.closest_color(particle.color,colors.xcolor_names)+"}")
|
||||
ff.write("{{({:05.2f},{:05.2f})}};\n".format(particle.squares[0].pos.x-self.particles[0].squares[0].pos.x,particle.squares[0].pos.y-self.particles[0].squares[0].pos.y))
|
||||
ff.write("{{({:05.2f},{:05.2f})}};\n".format(particle.elements[0].pos.x-self.particles[0].elements[0].pos.x,particle.elements[0].pos.y-self.particles[0].elements[0].pos.y))
|
||||
|
||||
ff.write("\\end{tikzpicture}\n")
|
||||
ff.write("\\end{document}\n")
|
||||
|
Reference in New Issue
Block a user