diff --git a/cross.py b/cross.py index 1160071..8f5518a 100644 --- a/cross.py +++ b/cross.py @@ -20,35 +20,35 @@ class Cross(): def draw(self): Color(*(self.color)) - Rectangle(pos=(self.pos.x-self.size*1.5,self.pos.y-self.size*0.5),size=(3*self.size,self.size)) - Rectangle(pos=(self.pos.x-self.size*0.5,self.pos.y-self.size*1.5),size=(self.size,3*self.size)) + Rectangle(pos=((self.pos.x-1.5)*self.size,(self.pos.y-0.5)*self.size),size=(3*self.size,self.size)) + Rectangle(pos=((self.pos.x-0.5)*self.size,(self.pos.y-1.5)*self.size),size=(self.size,3*self.size)) # stroke Color(1,1,1) Line(points=( - *(self.pos.x-self.size*0.5,self.pos.y-self.size*0.5), - *(self.pos.x-self.size*0.5,self.pos.y-self.size*1.5), - *(self.pos.x+self.size*0.5,self.pos.y-self.size*1.5), - *(self.pos.x+self.size*0.5,self.pos.y-self.size*0.5), - *(self.pos.x+self.size*1.5,self.pos.y-self.size*0.5), - *(self.pos.x+self.size*1.5,self.pos.y+self.size*0.5), - *(self.pos.x+self.size*0.5,self.pos.y+self.size*0.5), - *(self.pos.x+self.size*0.5,self.pos.y+self.size*1.5), - *(self.pos.x-self.size*0.5,self.pos.y+self.size*1.5), - *(self.pos.x-self.size*0.5,self.pos.y+self.size*0.5), - *(self.pos.x-self.size*1.5,self.pos.y+self.size*0.5), - *(self.pos.x-self.size*1.5,self.pos.y-self.size*0.5), - *(self.pos.x-self.size*0.5,self.pos.y-self.size*0.5), + *((self.pos.x-0.5)*self.size,(self.pos.y-0.5)*self.size), + *((self.pos.x-0.5)*self.size,(self.pos.y-1.5)*self.size), + *((self.pos.x+0.5)*self.size,(self.pos.y-1.5)*self.size), + *((self.pos.x+0.5)*self.size,(self.pos.y-0.5)*self.size), + *((self.pos.x+1.5)*self.size,(self.pos.y-0.5)*self.size), + *((self.pos.x+1.5)*self.size,(self.pos.y+0.5)*self.size), + *((self.pos.x+0.5)*self.size,(self.pos.y+0.5)*self.size), + *((self.pos.x+0.5)*self.size,(self.pos.y+1.5)*self.size), + *((self.pos.x-0.5)*self.size,(self.pos.y+1.5)*self.size), + *((self.pos.x-0.5)*self.size,(self.pos.y+0.5)*self.size), + *((self.pos.x-1.5)*self.size,(self.pos.y+0.5)*self.size), + *((self.pos.x-1.5)*self.size,(self.pos.y-0.5)*self.size), + *((self.pos.x-0.5)*self.size,(self.pos.y-0.5)*self.size), )) # check whether a cross at pos interacts with cross def check_interaction(self,pos): - return ((pos-self.pos)/self.size).int()**2>=5 + return (pos-self.pos).int()**2>=5 # find position along a line that comes in contact with the line going through pos in direction v def move_on_line_to_stick(self,pos,v): # relative to cross - return self.move_on_line_to_stick_relative((pos-self.pos)/self.size,v/self.size)*self.size+self.pos + return self.move_on_line_to_stick_relative(pos-self.pos,v)+self.pos def move_on_line_to_stick_relative(self,x,v): # if x is in the right quadrant @@ -136,8 +136,8 @@ class Cross_painter(Widget): def on_touch_down(self,touch): # create new cross if touch.button=="right": - if self.check_add(Point(touch.x,touch.y)): - new=Cross(touch.x,touch.y) + if self.check_add(Point(touch.x/Cross.size,touch.y/Cross.size)): + new=Cross(touch.x/Cross.size,touch.y/Cross.size) with self.canvas: new.draw() # add to list @@ -150,7 +150,7 @@ class Cross_painter(Widget): self.selected.selected=False # find cross under touch - self.selected=self.find_cross(Point(touch.x,touch.y)) + self.selected=self.find_cross(Point(touch.x/Cross.size,touch.y/Cross.size)) # select if self.selected!=None: self.selected.selected=True @@ -160,7 +160,7 @@ class Cross_painter(Widget): def on_touch_move(self,touch): # only move on left click if touch.button=="left" and self.selected!=None: - self.selected.pos=self.check_move(Point(touch.x,touch.y),self.selected) + self.selected.pos=self.check_move(Point(touch.x/Cross.size,touch.y/Cross.size),self.selected) # redraw self.canvas.clear() self.draw() @@ -169,7 +169,7 @@ class Cross_painter(Widget): # find the cross at position pos def find_cross(self,pos): for cross in self.crosses: - if cross_distx(pos,cross.pos)<=cross.size/2 or cross_disty(pos,cross.pos)<=cross.size/2: + if cross_distx(pos,cross.pos)<=0.5 or cross_disty(pos,cross.pos)<=0.5: return cross # none found return None