26 lines
616 B
Python
26 lines
616 B
Python
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()
|