diff --git a/mesa/examples/basic/conways_game_of_life/app.py b/mesa/examples/basic/conways_game_of_life/app.py index 168681b7ba6..e2219c9d2ff 100644 --- a/mesa/examples/basic/conways_game_of_life/app.py +++ b/mesa/examples/basic/conways_game_of_life/app.py @@ -20,12 +20,34 @@ def post_process(ax): model_params = { - "width": 50, - "height": 50, + "width": { + "type": "SliderInt", + "value": 50, + "label": "Width", + "min": 5, + "max": 60, + "step": 1, + }, + "height": { + "type": "SliderInt", + "value": 50, + "label": "Height", + "min": 5, + "max": 60, + "step": 1, + }, + "initial_fraction_alive": { + "type": "SliderFloat", + "value": 0.2, + "label": "Cells initially alive", + "min": 0, + "max": 1, + "step": 0.01, + }, } # Create initial model instance -model1 = ConwaysGameOfLife(50, 50) +model1 = ConwaysGameOfLife() # Create visualization elements. The visualization elements are solara components # that receive the model instance as a "prop" and display it in a certain way. diff --git a/mesa/examples/basic/conways_game_of_life/model.py b/mesa/examples/basic/conways_game_of_life/model.py index 6e81f690763..f61f71bf623 100644 --- a/mesa/examples/basic/conways_game_of_life/model.py +++ b/mesa/examples/basic/conways_game_of_life/model.py @@ -6,7 +6,7 @@ class ConwaysGameOfLife(Model): """Represents the 2-dimensional array of cells in Conway's Game of Life.""" - def __init__(self, width=50, height=50, seed=None): + def __init__(self, width=50, height=50, initial_fraction_alive=0.2, seed=None): """Create a new playing area of (width, height) cells.""" super().__init__(seed=seed) # Use a simple grid, where edges wrap around. @@ -16,7 +16,7 @@ def __init__(self, width=50, height=50, seed=None): # ALIVE and some to DEAD. for _contents, (x, y) in self.grid.coord_iter(): cell = Cell((x, y), self) - if self.random.random() < 0.1: + if self.random.random() < initial_fraction_alive: cell.state = cell.ALIVE self.grid.place_agent(cell, (x, y))