Skip to content

Commit

Permalink
examples: Convert color_patches to simple namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
rht authored and tpike3 committed May 19, 2022
1 parent 59b58bc commit d4bf534
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 5 additions & 7 deletions examples/color_patches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

from collections import Counter

from mesa import Model, Agent
from mesa.time import SimultaneousActivation
from mesa.space import Grid
import mesa


class ColorCell(Agent):
class ColorCell(mesa.Agent):
"""
Represents a cell's opinion (visualized by a color)
"""
Expand Down Expand Up @@ -63,7 +61,7 @@ def advance(self):
self._state = self._next_state


class ColorPatches(Model):
class ColorPatches(mesa.Model):
"""
represents a 2D lattice where agents live
"""
Expand All @@ -74,8 +72,8 @@ def __init__(self, width=20, height=20):
The agents next state is first determined before updating the grid
"""

self._grid = Grid(width, height, torus=False)
self._schedule = SimultaneousActivation(self)
self._grid = mesa.space.Grid(width, height, torus=False)
self._schedule = mesa.time.SimultaneousActivation(self)

# self._grid.coord_iter()
# --> should really not return content + col + row
Expand Down
7 changes: 3 additions & 4 deletions examples/color_patches/color_patches/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"""
# import webbrowser

from mesa.visualization.modules import CanvasGrid
from mesa.visualization.ModularVisualization import ModularServer
import mesa

from .model import ColorPatches

Expand Down Expand Up @@ -55,11 +54,11 @@ def color_patch_draw(cell):
return portrayal


canvas_element = CanvasGrid(
canvas_element = mesa.visualization.CanvasGrid(
color_patch_draw, grid_rows, grid_cols, canvas_width, canvas_height
)

server = ModularServer(
server = mesa.visualization.ModularServer(
ColorPatches,
[canvas_element],
"Color Patches",
Expand Down

0 comments on commit d4bf534

Please sign in to comment.