Skip to content

Commit 1a5e104

Browse files
authored
GoL_fast: Visualize the Game of Life cells using the PropertyLayer (#214)
Tested with latest Mesa 3.0.0b0
1 parent 84542d4 commit 1a5e104

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed
Loading

examples/conways_game_of_life_fast/Readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Conway's Game of Life (Fast)
22
This example demonstrates a fast and efficient implementation of Conway's Game of Life using the [`PropertyLayer`](https://github.com/projectmesa/mesa/pull/1898) from the Mesa framework.
33

4+
![GoL_fast_screenshot.png](GoL_fast_screenshot.png)
5+
46
### Overview
57
Conway's [Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) is a classic cellular automaton where each cell on a grid can either be alive or dead. The state of each cell changes over time based on a set of simple rules that depend on the number of alive neighbors.
68

@@ -18,8 +20,8 @@ The model is benchmarked in https://github.com/projectmesa/mesa/pull/1898#issuec
1820

1921
### Getting Started
2022
#### Prerequisites
21-
- Python 3.9 or higher
22-
- Mesa 2.3 or higher
23+
- Python 3.10 or higher
24+
- Mesa 2.3 or higher (3.0.0b0 or higher for the visualisation)
2325
- NumPy and SciPy
2426

2527
#### Running the Model

examples/conways_game_of_life_fast/app.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,49 @@
1-
from mesa.visualization import SolaraViz, make_plot_measure
1+
from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib
22
from model import GameOfLifeModel
33

4+
propertylayer_portrayal = {
5+
"cell_layer": {
6+
"color": "Black",
7+
"alpha": 1,
8+
"colorbar": False,
9+
},
10+
}
11+
412
model_params = {
513
"width": {
614
"type": "SliderInt",
7-
"value": 10,
15+
"value": 30,
816
"label": "Width",
917
"min": 5,
10-
"max": 25,
18+
"max": 60,
1119
"step": 1,
1220
},
1321
"height": {
1422
"type": "SliderInt",
15-
"value": 10,
23+
"value": 30,
1624
"label": "Height",
1725
"min": 5,
18-
"max": 25,
26+
"max": 60,
1927
"step": 1,
2028
},
29+
"alive_fraction": {
30+
"type": "SliderFloat",
31+
"value": 0.2,
32+
"label": "Cells alive",
33+
"min": 0,
34+
"max": 1,
35+
"step": 0.01,
36+
},
2137
}
2238

23-
gol = GameOfLifeModel(10, 10)
39+
gol = GameOfLifeModel()
2440

41+
layer_viz = make_space_matplotlib(propertylayer_portrayal=propertylayer_portrayal)
2542
TotalAlivePlot = make_plot_measure("Cells alive")
26-
FractionAlivePlot = make_plot_measure("Fraction alive")
27-
2843

2944
page = SolaraViz(
3045
gol,
31-
components=[TotalAlivePlot, FractionAlivePlot],
46+
components=[layer_viz, TotalAlivePlot],
3247
model_params=model_params,
3348
name="Game of Life Model",
3449
)
35-
page # noqa

0 commit comments

Comments
 (0)