repl.it
@turbio/

game of life (part 3)

Python

No description

fork
loading
Files
  • main.py
  • board.py
  • glider.txt
  • life.gif
main.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
import board
from PIL import Image

width = 50
height = 50

b = board.fromFile("./glider.txt", 30, 30)

frames = []

for i in range(100):
  print("frame", str(i))
  
  b = b.step()

  img = Image.new('RGB', (width, height), color=(255, 255, 255))
  
  b.each(
    lambda x, y, v:
      img.putpixel((x, y), (0, 0, 0) if v else (255, 255 , 255))
  )
  
  img = img.resize((width * 5, height * 5), Image.NEAREST)
  
  frames.append(img)
  
frames[0].save(
  "life.gif",
  save_all=True,
  append_images=frames[1:],
  loop=0,
  duration=100
)
Fetching token
?