-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbinary_tree.py
More file actions
23 lines (20 loc) · 765 Bytes
/
Copy pathbinary_tree.py
File metadata and controls
23 lines (20 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import random
from make_animation import MakeAnimation
class BinaryTree:
def mutate(grid, animation = False):
filenames = []
frame = 0
for cell in grid.each_cell():
neighbors = []
if cell.north: neighbors.append(cell.north)
if cell.east: neighbors.append(cell.east)
if len(neighbors) > 0:
index = random.randrange(len(neighbors))
neighbor = neighbors[index]
cell.link(neighbor)
if animation:
frame += 1
grid.to_png(20, str(frame))
filenames.append("./exports/maze"+str(frame)+".png")
if animation:
MakeAnimation(filenames, 'binary_tree.gif')