transparency for grids

This commit is contained in:
Ian Jauslin 2021-12-10 10:55:04 -05:00
parent f0f090315a
commit 1c1e2ad6f7
2 changed files with 10 additions and 4 deletions

View File

@ -53,13 +53,18 @@ class Painter(Widget):
def draw(self): def draw(self):
self.canvas.clear() self.canvas.clear()
with self.canvas: with self.canvas:
# draw order: particles, then grids, then transparent particles
for particle in self.particles:
particle.draw()
# draw grids # draw grids
for particle in self.particles: for particle in self.particles:
if particle.grid>0: if particle.grid>0:
self.draw_grid(particle.squares[0].pos,particle.grid) self.draw_grid(particle.squares[0].pos,particle.grid)
for particle in self.particles: for particle in self.particles:
particle.draw() particle.draw(alpha=0.5)
def draw_grid(self,pos,mesh): def draw_grid(self,pos,mesh):
# height offset due to status bar and command prompt # height offset due to status bar and command prompt

View File

@ -18,14 +18,15 @@ class Polyomino():
self.grid=kwargs.get("grid",0) self.grid=kwargs.get("grid",0)
# draw function # draw function
def draw(self): def draw(self,**kwargs):
alpha=kwargs.get("alpha",1)
# set color # set color
if not self.selected: if not self.selected:
Color(*self.color) Color(*self.color,alpha)
else: else:
(r,g,b)=self.color (r,g,b)=self.color
# darken selected # darken selected
Color(r/2,g/2,b/2) Color(r/2,g/2,b/2,alpha)
for square in self.squares: for square in self.squares:
Rectangle(pos=((square.pos.x-0.5)*square.size,(square.pos.y-0.5)*square.size),size=(square.size,square.size)) Rectangle(pos=((square.pos.x-0.5)*square.size,(square.pos.y-0.5)*square.size),size=(square.size,square.size))