rescale space so cross size is 1

This commit is contained in:
Ian Jauslin 2021-09-28 15:35:41 -04:00
parent 4ffddd5bef
commit 6851e1ab32

View File

@ -20,35 +20,35 @@ class Cross():
def draw(self): def draw(self):
Color(*(self.color)) 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-1.5)*self.size,(self.pos.y-0.5)*self.size),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-0.5)*self.size,(self.pos.y-1.5)*self.size),size=(self.size,3*self.size))
# stroke # stroke
Color(1,1,1) Color(1,1,1)
Line(points=( Line(points=(
*(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-self.size*0.5,self.pos.y-self.size*1.5), *((self.pos.x-0.5)*self.size,(self.pos.y-1.5)*self.size),
*(self.pos.x+self.size*0.5,self.pos.y-self.size*1.5), *((self.pos.x+0.5)*self.size,(self.pos.y-1.5)*self.size),
*(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+self.size*1.5,self.pos.y-self.size*0.5), *((self.pos.x+1.5)*self.size,(self.pos.y-0.5)*self.size),
*(self.pos.x+self.size*1.5,self.pos.y+self.size*0.5), *((self.pos.x+1.5)*self.size,(self.pos.y+0.5)*self.size),
*(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+self.size*0.5,self.pos.y+self.size*1.5), *((self.pos.x+0.5)*self.size,(self.pos.y+1.5)*self.size),
*(self.pos.x-self.size*0.5,self.pos.y+self.size*1.5), *((self.pos.x-0.5)*self.size,(self.pos.y+1.5)*self.size),
*(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-self.size*1.5,self.pos.y+self.size*0.5), *((self.pos.x-1.5)*self.size,(self.pos.y+0.5)*self.size),
*(self.pos.x-self.size*1.5,self.pos.y-self.size*0.5), *((self.pos.x-1.5)*self.size,(self.pos.y-0.5)*self.size),
*(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),
)) ))
# check whether a cross at pos interacts with cross # check whether a cross at pos interacts with cross
def check_interaction(self,pos): 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 # 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): def move_on_line_to_stick(self,pos,v):
# relative to cross # 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): def move_on_line_to_stick_relative(self,x,v):
# if x is in the right quadrant # if x is in the right quadrant
@ -136,8 +136,8 @@ class Cross_painter(Widget):
def on_touch_down(self,touch): def on_touch_down(self,touch):
# create new cross # create new cross
if touch.button=="right": if touch.button=="right":
if self.check_add(Point(touch.x,touch.y)): if self.check_add(Point(touch.x/Cross.size,touch.y/Cross.size)):
new=Cross(touch.x,touch.y) new=Cross(touch.x/Cross.size,touch.y/Cross.size)
with self.canvas: with self.canvas:
new.draw() new.draw()
# add to list # add to list
@ -150,7 +150,7 @@ class Cross_painter(Widget):
self.selected.selected=False self.selected.selected=False
# find cross under touch # 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 # select
if self.selected!=None: if self.selected!=None:
self.selected.selected=True self.selected.selected=True
@ -160,7 +160,7 @@ class Cross_painter(Widget):
def on_touch_move(self,touch): def on_touch_move(self,touch):
# only move on left click # only move on left click
if touch.button=="left" and self.selected!=None: 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 # redraw
self.canvas.clear() self.canvas.clear()
self.draw() self.draw()
@ -169,7 +169,7 @@ class Cross_painter(Widget):
# find the cross at position pos # find the cross at position pos
def find_cross(self,pos): def find_cross(self,pos):
for cross in self.crosses: 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 return cross
# none found # none found
return None return None