-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathapp.py
85 lines (74 loc) · 1.67 KB
/
app.py
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
84
85
from mesa.visualization import SolaraViz
from mesa.visualization.components.matplotlib_components import make_mpl_space_component
from termites.model import TermiteModel
wood_chip_portrayal = {
"woodcell": {
"color": "blue",
"alpha": 0.6,
"colorbar": False,
"vmin": 0,
"vmax": 2,
},
}
def agent_portrayal(agent):
return {
"marker": ">",
"color": "red" if agent.has_woodchip else "black",
"size": 10,
}
model_params = {
"seed": {
"type": "InputText",
"value": 42,
"label": "Seed",
},
"num_termites": {
"type": "SliderInt",
"value": 100,
"label": "No. of Termites",
"min": 10,
"max": 1000,
"step": 1,
},
"wood_chip_density": {
"type": "SliderFloat",
"value": 0.1,
"label": "Wood Chip Density",
"min": 0.01,
"max": 1,
"step": 0.1,
},
"width": {
"type": "SliderInt",
"value": 100,
"label": "Width",
"min": 10,
"max": 500,
"step": 1,
},
"height": {
"type": "SliderInt",
"value": 100,
"label": "Height",
"min": 10,
"max": 500,
"step": 1,
},
}
model = TermiteModel()
def post_process(ax):
ax.set_aspect("equal")
ax.set_xticks([])
ax.set_yticks([])
woodchips_space = make_mpl_space_component(
agent_portrayal=agent_portrayal,
propertylayer_portrayal=wood_chip_portrayal,
post_process=post_process,
draw_grid=False,
)
page = SolaraViz(
model,
components=[woodchips_space],
model_params=model_params,
name="Termites Model",
)