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

26 lines
616 B
Python
Raw Normal View History

2019-02-23 19:38:37 +00:00
import matplotlib.pyplot as plt
import numpy as np
from model import prepare_model
from backend import total_living_cells
from executor import execute_tick
def cells_alive_at_ticks(model, ticks):
for i in range(ticks):
execute_tick(model)
cell_count = total_living_cells(model)
yield i, cell_count
plot_data = {
0.3 : ("r", "p=0.3")
, 0.5: ("g", "p=0.5")
, 0.7: ("b", "p=0.7")
}
for p, (color, label) in plot_data.items():
model = prepare_model(100, p)
living_cells = np.array(list(cells_alive_at_ticks(model, 1000)))
plt.plot(living_cells[:, 0], living_cells[:, 1], color, label=label)
plt.show()