From 1c1e2ad6f730d88e3f1ad63cc42810af6c71cc39 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Fri, 10 Dec 2021 10:55:04 -0500 Subject: [PATCH] transparency for grids --- painter.py | 7 ++++++- polyomino.py | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/painter.py b/painter.py index 454d26b..1a28ebc 100644 --- a/painter.py +++ b/painter.py @@ -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 diff --git a/polyomino.py b/polyomino.py index 1b5aa22..4e39126 100644 --- a/polyomino.py +++ b/polyomino.py @@ -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))