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):
self.canvas.clear()
with self.canvas:
# draw order: particles, then grids, then transparent particles
for particle in self.particles:
particle.draw()
# draw grids
for particle in self.particles:
if particle.grid>0:
self.draw_grid(particle.squares[0].pos,particle.grid)
for particle in self.particles:
particle.draw()
particle.draw(alpha=0.5)
def draw_grid(self,pos,mesh):
# height offset due to status bar and command prompt

View File

@ -18,14 +18,15 @@ class Polyomino():
self.grid=kwargs.get("grid",0)
# draw function
def draw(self):
def draw(self,**kwargs):
alpha=kwargs.get("alpha",1)
# set color
if not self.selected:
Color(*self.color)
Color(*self.color,alpha)
else:
(r,g,b)=self.color
# darken selected
Color(r/2,g/2,b/2)
Color(r/2,g/2,b/2,alpha)
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))