added exam ex 14
This commit is contained in:
parent
b3b6692de8
commit
a685f530f6
34
exam/ex14/main.py
Normal file
34
exam/ex14/main.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
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")
|
Loading…
Reference in New Issue
Block a user