forked from mesa/mesa-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
83 lines (72 loc) · 1.45 KB
/
app.py
File metadata and controls
83 lines (72 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""handles the definition of the canvas parameters and
the drawing of the model representation on the canvas
"""
# import webbrowser
from color_patches.model import ColorPatches
from mesa.visualization import (
SolaraViz,
make_space_component,
)
from mesa.visualization.user_param import (
Slider,
)
_COLORS = [
"Aqua",
"Blue",
"Fuchsia",
"Gray",
"Green",
"Lime",
"Maroon",
"Navy",
"Olive",
"Orange",
"Purple",
"Red",
"Silver",
"Teal",
"White",
"Yellow",
]
grid_rows = 50
grid_cols = 25
cell_size = 10
canvas_width = grid_rows * cell_size
canvas_height = grid_cols * cell_size
def color_patch_draw(cell):
"""This function is registered with the visualization server to be called
each tick to indicate how to draw the cell in its current state.
:param cell: the cell in the simulation
:return: the portrayal dictionary.
"""
if cell is None:
return
return {
"color": _COLORS[cell.state],
"size": 100,
}
space_component = make_space_component(
color_patch_draw,
draw_grid=False,
)
model = ColorPatches()
model_params = {
"width": Slider(
"Grid Width",
grid_rows,
5,
100,
),
"height": Slider(
"Grid Height",
grid_cols,
5,
100,
),
}
page = SolaraViz(
model,
components=[space_component],
model_params=model_params,
name="Color Patches",
)