Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoL_fast: Visualize the Game of Life cells using the PropertyLayer #214

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions examples/conways_game_of_life_fast/Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Conway's Game of Life (Fast)
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.

![GoL_fast_screenshot.png](GoL_fast_screenshot.png)

### Overview
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.

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

### Getting Started
#### Prerequisites
- Python 3.9 or higher
- Mesa 2.3 or higher
- Python 3.10 or higher
- Mesa 2.3 or higher (3.0.0b0 or higher for the visualisation)
- NumPy and SciPy

#### Running the Model
Expand Down
34 changes: 24 additions & 10 deletions examples/conways_game_of_life_fast/app.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
from mesa.visualization import SolaraViz, make_plot_measure
from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib
from model import GameOfLifeModel

propertylayer_portrayal = {
"cell_layer": {
"color": "Black",
"alpha": 1,
"colorbar": False,
},
}

model_params = {
"width": {
"type": "SliderInt",
"value": 10,
"value": 30,
"label": "Width",
"min": 5,
"max": 25,
"max": 60,
"step": 1,
},
"height": {
"type": "SliderInt",
"value": 10,
"value": 30,
"label": "Height",
"min": 5,
"max": 25,
"max": 60,
"step": 1,
},
"alive_fraction": {
"type": "SliderFloat",
"value": 0.2,
"label": "Cells alive",
"min": 0,
"max": 1,
"step": 0.01,
},
}

gol = GameOfLifeModel(10, 10)
gol = GameOfLifeModel()

layer_viz = make_space_matplotlib(propertylayer_portrayal=propertylayer_portrayal)
TotalAlivePlot = make_plot_measure("Cells alive")
FractionAlivePlot = make_plot_measure("Fraction alive")


page = SolaraViz(
gol,
components=[TotalAlivePlot, FractionAlivePlot],
components=[layer_viz, TotalAlivePlot],
model_params=model_params,
name="Game of Life Model",
)
page # noqa
Loading