Fix grid drawing

This commit is contained in:
Ian Jauslin 2022-09-23 13:17:35 -04:00
parent 9cb25730eb
commit 42e9f60c4e
2 changed files with 24 additions and 12 deletions

View File

@ -34,5 +34,5 @@ class Square_lattice(Lattice):
# draw
def draw(self,painter):
painter.draw_grid(Point(0,0),self.spacing)
painter.draw_grid(Point(self.spacing/2,self.spacing/2),self.spacing)

View File

@ -22,8 +22,7 @@ class Painter(Widget):
self.particles=[]
# underlying lattice
#self.lattice=None
self.lattice=Square_lattice()
self.lattice=None
# particle under mouse
self.undermouse=None
@ -96,17 +95,30 @@ class Painter(Widget):
# height offset due to status bar and command prompt
height_offset=self.app.status_bar.height+self.app.command_prompt.height
# vertical lines
# offest wrt 0
offset=(pos.x-0.5)%mesh
for i in range(math.floor((self.width/Square_element.size-offset)/mesh)+1):
# lines right of pos
xx=pos.x+mesh/2
while self.pos_tocoord_x(xx)<self.width:
Color(1,1,1)
Line(points=((i*mesh+offset)*Square_element.size,height_offset,(i*mesh+offset)*Square_element.size,self.height+height_offset))
# horizontal lines
# offset wrt 0
offset=(pos.y-0.5)%1-height_offset/Square_element.size
for i in range(math.floor((self.height/Square_element.size-offset)/mesh)+1):
Line(points=(self.pos_tocoord_x(xx),height_offset,self.pos_tocoord_x(xx),self.height+height_offset))
xx+=mesh
# lines left of pos
xx=pos.x-mesh/2
while self.pos_tocoord_x(xx)>0:
Color(1,1,1)
Line(points=(0,(i*mesh+offset)*Square_element.size+height_offset,self.width,(i*mesh+offset)*Square_element.size+height_offset))
Line(points=(self.pos_tocoord_x(xx),height_offset,self.pos_tocoord_x(xx),self.height+height_offset))
xx-=mesh
# lines above pos
yy=pos.y+mesh/2
while self.pos_tocoord_y(yy)<self.height:
Color(1,1,1)
Line(points=(0,self.pos_tocoord_y(yy),self.width,self.pos_tocoord_y(yy)))
yy+=mesh
# lines below pos
yy=pos.y-mesh/2
while self.pos_tocoord_y(yy)>0:
Color(1,1,1)
Line(points=(0,self.pos_tocoord_y(yy),self.width,self.pos_tocoord_y(yy)))
yy-=mesh
# respond to keyboard