Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"""

# import webbrowser

import mesa

from .model import ColorPatches
from color_patches.model import ColorPatches
from mesa.visualization import (
SolaraViz,
make_space_component,
)

_COLORS = [
"Aqua",
Expand Down Expand Up @@ -50,19 +51,19 @@ def color_patch_draw(cell):
portrayal = {"Shape": "rect", "w": 1, "h": 1, "Filled": "true", "Layer": 0}
portrayal["x"] = cell.get_row()
portrayal["y"] = cell.get_col()
portrayal["Color"] = _COLORS[cell.get_state()]
portrayal["color"] = _COLORS[cell.state]
return portrayal


canvas_element = mesa.visualization.CanvasGrid(
color_patch_draw, grid_rows, grid_cols, canvas_width, canvas_height
space_component = make_space_component(
color_patch_draw,
draw_grid=False,
)

server = mesa.visualization.ModularServer(
ColorPatches,
[canvas_element],
"Color Patches",
{"width": grid_rows, "height": grid_cols},
model = ColorPatches()
page = SolaraViz(
model,
components=[space_component],
model_params={"width": grid_rows, "height": grid_cols},
name="Color Patches",
)

# webbrowser.open('http://127.0.0.1:8521') # TODO: make this configurable
10 changes: 8 additions & 2 deletions examples/color_patches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
from collections import Counter

import mesa
from mesa.discrete_space.cell_agent import (
CellAgent,
)
from mesa.discrete_space.grid import (
OrthogonalMooreGrid,
)


class ColorCell(mesa.experimental.cell_space.CellAgent):
class ColorCell(CellAgent):
"""
Represents a cell's opinion (visualized by a color)
"""
Expand Down Expand Up @@ -66,7 +72,7 @@ def __init__(self, width=20, height=20):
The agents next state is first determined before updating the grid
"""
super().__init__()
self._grid = mesa.experimental.cell_space.OrthogonalMooreGrid(
self._grid = OrthogonalMooreGrid(
(width, height), torus=False, random=self.random
)

Expand Down
3 changes: 2 additions & 1 deletion examples/color_patches/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mesa~=2.0
mesa[viz]>=3.0
networkx
3 changes: 0 additions & 3 deletions examples/color_patches/run.py

This file was deleted.