Skip to content

Commit 1fe3402

Browse files
added plotting of the canvas
1 parent 516e778 commit 1fe3402

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

game_o_life.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
import random, time, sys
3232
from matplotlib import pyplot as plt
3333
import matplotlib.animation as animation
34+
from matplotlib.colors import ListedColormap
3435

3536
usage_doc='Usage of script: script_nama <size_of_canvas:int>'
3637

38+
choice = [0]*100 + [1]*10
39+
random.shuffle(choice)
40+
3741
def create_canvas(size):
3842
canvas = [ [False for i in range(size)] for j in range(size)]
3943
return canvas
@@ -102,7 +106,13 @@ def __judge_point(pt,neighbours):
102106
seed(c)
103107
fig, ax = plt.subplots()
104108
fig.show()
105-
while True:
106-
c = run(c)
107-
ax.matshow(c)
108-
fig.canvas.draw()
109+
cmap = ListedColormap(['w','k'])
110+
try:
111+
while True:
112+
c = run(c)
113+
ax.matshow(c,cmap=cmap)
114+
fig.canvas.draw()
115+
ax.cla()
116+
except KeyboardInterrupt:
117+
# do nothing.
118+
pass

0 commit comments

Comments
 (0)