Fix grid drawing
This commit is contained in:
parent
9cb25730eb
commit
42e9f60c4e
@ -34,5 +34,5 @@ class Square_lattice(Lattice):
|
|||||||
|
|
||||||
# draw
|
# draw
|
||||||
def draw(self,painter):
|
def draw(self,painter):
|
||||||
painter.draw_grid(Point(0,0),self.spacing)
|
painter.draw_grid(Point(self.spacing/2,self.spacing/2),self.spacing)
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ class Painter(Widget):
|
|||||||
self.particles=[]
|
self.particles=[]
|
||||||
|
|
||||||
# underlying lattice
|
# underlying lattice
|
||||||
#self.lattice=None
|
self.lattice=None
|
||||||
self.lattice=Square_lattice()
|
|
||||||
|
|
||||||
# particle under mouse
|
# particle under mouse
|
||||||
self.undermouse=None
|
self.undermouse=None
|
||||||
@ -96,17 +95,30 @@ class Painter(Widget):
|
|||||||
# height offset due to status bar and command prompt
|
# height offset due to status bar and command prompt
|
||||||
height_offset=self.app.status_bar.height+self.app.command_prompt.height
|
height_offset=self.app.status_bar.height+self.app.command_prompt.height
|
||||||
# vertical lines
|
# vertical lines
|
||||||
# offest wrt 0
|
# lines right of pos
|
||||||
offset=(pos.x-0.5)%mesh
|
xx=pos.x+mesh/2
|
||||||
for i in range(math.floor((self.width/Square_element.size-offset)/mesh)+1):
|
while self.pos_tocoord_x(xx)<self.width:
|
||||||
Color(1,1,1)
|
Color(1,1,1)
|
||||||
Line(points=((i*mesh+offset)*Square_element.size,height_offset,(i*mesh+offset)*Square_element.size,self.height+height_offset))
|
Line(points=(self.pos_tocoord_x(xx),height_offset,self.pos_tocoord_x(xx),self.height+height_offset))
|
||||||
# horizontal lines
|
xx+=mesh
|
||||||
# offset wrt 0
|
# lines left of pos
|
||||||
offset=(pos.y-0.5)%1-height_offset/Square_element.size
|
xx=pos.x-mesh/2
|
||||||
for i in range(math.floor((self.height/Square_element.size-offset)/mesh)+1):
|
while self.pos_tocoord_x(xx)>0:
|
||||||
Color(1,1,1)
|
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
|
# respond to keyboard
|
||||||
|
Loading…
Reference in New Issue
Block a user