diff --git a/examples/conways_game_of_life_fast/GoL_fast_screenshot.png b/examples/conways_game_of_life_fast/GoL_fast_screenshot.png new file mode 100644 index 00000000..9b7b26f5 Binary files /dev/null and b/examples/conways_game_of_life_fast/GoL_fast_screenshot.png differ diff --git a/examples/conways_game_of_life_fast/Readme.md b/examples/conways_game_of_life_fast/Readme.md index 5aaf14b7..b3d6218b 100644 --- a/examples/conways_game_of_life_fast/Readme.md +++ b/examples/conways_game_of_life_fast/Readme.md @@ -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. @@ -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 diff --git a/examples/conways_game_of_life_fast/app.py b/examples/conways_game_of_life_fast/app.py index 568f0641..a3084905 100644 --- a/examples/conways_game_of_life_fast/app.py +++ b/examples/conways_game_of_life_fast/app.py @@ -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