-
Notifications
You must be signed in to change notification settings - Fork 0
/
a-blinker.py
45 lines (30 loc) · 855 Bytes
/
a-blinker.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
41
42
43
44
45
# -*- coding: utf-8 -*-
"""
Game of life script with animated evolution
Created on Tue Jan 15 12:37:52 2019
@author: shakes
"""
import conway
N = 64
#create the game of life object
life = conway.GameOfLife(N)
life.insertBlinker((0,0))
cells = life.getStates() #initial state
#-------------------------------
#plot cells
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
plt.gray()
img = plt.imshow(cells, animated=True)
def animate(i):
"""perform animation step"""
global life
life.evolve()
cellsUpdated = life.getStates()
img.set_array(cellsUpdated)
return img,
interval = 50 #ms
#animate 24 frames with interval between them calling animate function at each frame
ani = animation.FuncAnimation(fig, animate, frames=24, interval=interval, blit=True)
plt.show()