-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimpleContinuousModule.py
33 lines (29 loc) · 1.2 KB
/
SimpleContinuousModule.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
from mesa.visualization.ModularVisualization import VisualizationElement
class SimpleCanvas(VisualizationElement):
local_includes = ["./simple_continuous_canvas.js"]
portrayal_method = None
canvas_height = 500
canvas_width = 500
def __init__(self, portrayal_method, canvas_height=500, canvas_width=500):
'''
Instantiate a new SimpleCanvas
'''
self.portrayal_method = portrayal_method
self.canvas_height = canvas_height
self.canvas_width = canvas_width
new_element = ("new Simple_Continuous_Module({}, {})".
format(self.canvas_width, self.canvas_height))
self.js_code = "elements.push(" + new_element + ");"
def render(self, model):
space_state = []
for obj in model.schedule.agents:
portrayal = self.portrayal_method(obj)
x, y = obj.pos
x = ((x - model.space.x_min) /
(model.space.x_max - model.space.x_min))
y = ((y - model.space.y_min) /
(model.space.y_max - model.space.y_min))
portrayal["x"] = x
portrayal["y"] = y
space_state.append(portrayal)
return space_state