Skip to content
Snippets Groups Projects
Verified Commit 82759a2b authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

use gradient of colors in path

parent 0a20aaaf
Branches
No related tags found
No related merge requests found
......@@ -25,9 +25,9 @@ COLORS = {
"walls": (200, 200, 200),
"path": (100, 0, 0),
"path link": (80, 0, 0),
"path ends": (255, 165, 0),
"path ends link": (255 * 0.7, 165 * 0.7, 0),
"path ends ends": (255, 0, 255),
"path start": (255, 165, 0),
"path end": (165, 0, 255),
"pause": (255, 0, 0),
}
STYLE = {
......@@ -211,9 +211,17 @@ class Canva:
y_b = (.5 + b // maze["width"]) * maze["size"]
if complete:
p = i / (len(path) - 1)
rs, gs, bs = COLORS["path start"]
re, ge, be = COLORS["path end"]
c = (
p * rs + (1 - p) * re,
p * gs + (1 - p) * ge,
p * bs + (1 - p) * be,
)
pygame.draw.line(
self.screen,
COLORS["path ends link"],
c,
(x_a, y_a),
(x_b, y_b),
width=int(maze["size"] * STYLE["link width"]),
......@@ -227,24 +235,25 @@ class Canva:
width=int(maze["size"] * STYLE["link width"]),
)
for i, a in enumerate(path):
x_a = (.5 + a % maze["width"]) * maze["size"]
y_a = (.5 + a // maze["width"]) * maze["size"]
d = int(maze["size"] * STYLE["grid"].m)
r = int(maze["size"] * STYLE["grid"].r)
a = (x_a - d // 2, y_a - d // 2, d, d)
b = (x_b - d // 2, y_b - d // 2, d, d)
if complete:
if i == 0:
pygame.draw.rect(self.screen, COLORS["path ends ends"], a, border_radius=r)
pygame.draw.rect(self.screen, COLORS["path ends"], b, border_radius=r)
elif i == len(path) - 2:
pygame.draw.rect(self.screen, COLORS["path ends"], a, border_radius=r)
pygame.draw.rect(self.screen, COLORS["path ends ends"], b, border_radius=r)
else:
pygame.draw.rect(self.screen, COLORS["path ends"], a, border_radius=r)
pygame.draw.rect(self.screen, COLORS["path ends"], b, border_radius=r)
p = i / (len(path) - 1)
rs, gs, bs = COLORS["path start"]
re, ge, be = COLORS["path end"]
c = (
p * rs + (1 - p) * re,
p * gs + (1 - p) * ge,
p * bs + (1 - p) * be,
)
pygame.draw.rect(self.screen, c, a, border_radius=r)
else:
pygame.draw.rect(self.screen, COLORS["path"], a, border_radius=r)
pygame.draw.rect(self.screen, COLORS["path"], b, border_radius=r)
# walls
h = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment