-
Notifications
You must be signed in to change notification settings - Fork 0
/
coloring_demo.py
40 lines (32 loc) · 1.31 KB
/
coloring_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from typing import List
from core.colored_grid import ColoredGrid
from PIL.Image import Image
# from tqdm import tqdm
# from generators.binary_tree import BinaryTree
from generators.sidewinder import Sidewinder
grid = ColoredGrid(50, 50)
Sidewinder.on(grid)
# - start = grid[grid.rows / 2, grid.columns / 2]
# start = grid[int(grid.nr_rows / 2)][int(grid.nr_cols / 2)]
start = grid[0][0]
images: List[Image] = []
# TODO: This updates the colors of the gif based on the distance map. So colors are updated along the way.
# I could also generate the final distance map and just animate the coloring. So, instead of to_png() I'd
# have a to_gif, that just animates the colors based on the final distances. Would be more efficient.
# TODO: Another cool feature would be to not draw the colors in rectangles, but do it in a form of scanline,
# so the floodfill would be smoother, instead of appearing in a cube.
# for distances in start.distances_stepwise():
# # print("visualising distance")
# grid.distances(distances)
# images.append(grid.to_png())
# image.save(f"results/animated_{frame_counter}.png")
distances = start.distances()
grid.distances(distances)
images = grid.to_gif()
images[0].save(
"results/dijkstra.gif",
save_all=True,
append_images=images[1:],
optimize=True,
duration=20,
)