-
Notifications
You must be signed in to change notification settings - Fork 0
/
e-convolved_2.py
50 lines (34 loc) · 1020 Bytes
/
e-convolved_2.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
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Game of life script with animated evolution
Created on Tue Jan 15 12:37:52 2019
@author: shakes
"""
import convolve
padding = 10
#read plain text file
with open("e-pattern_2.rle", "r") as text_file:
txtString = text_file.read()
#create the game of life object
life = convolve.GameOfLife(N=1024, fastMode=True)
life.insertFromRLE(txtString, padding)
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)
#~ animate(0)
plt.show()