scientific-programming-exer.../exam/ex14/main.py

35 lines
829 B
Python
Raw Normal View History

2019-02-23 20:32:04 +00:00
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import numpy as np
import sys
sys.path.append("../ex13/")
from model import prepare_model
from backend import CELL_IS_ALIVE
from executor import execute_tick
fig = plt.figure(figsize=(7, 7))
ax = fig.add_axes([0, 0, 1, 1], frameon=False)
ax.set_xlim(0, 100)
ax.set_xticks([])
ax.set_ylim(0, 100)
ax.set_yticks([])
model = prepare_model(100, 0.2)
scat, = ax.plot(*np.where((model & CELL_IS_ALIVE) == 1), "s", color="black")
frames = 100
def update(i):
execute_tick(model)
scat.set_data(*np.where((model & CELL_IS_ALIVE) == 1))
print("%.2f" % ((i / frames) * 100), "%", end="\r")
animation = ani.FuncAnimation(fig, update, range(frames), interval=1)
animation.save("output/animation.gif", dpi=80, writer='imagemagick')
print("\noutput/animation.gif")