Coverage for src/scicom/randomletters/SimpleContinuousModule.py: 0%
24 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-15 13:26 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-15 13:26 +0200
1import mesa
4class SimpleCanvas(mesa.visualization.VisualizationElement):
5 local_includes = ["randomletters/simple_continuous_canvas.js"]
6 local_css_includes = ["randomletters/map.png"]
7 portrayal_method = None
8 canvas_height = 720
9 canvas_width = 1280
11 def __init__(self, portrayal_method, canvas_height=720, canvas_width=1280):
12 """
13 Instantiate a new SimpleCanvas
14 """
15 self.portrayal_method = portrayal_method
16 self.canvas_height = canvas_height
17 self.canvas_width = canvas_width
18 new_element = "new Simple_Continuous_Module({}, {})".format(
19 self.canvas_width, self.canvas_height
20 )
21 self.js_code = "elements.push(" + new_element + ");"
23 def render(self, model):
24 space_state = []
25 for obj in model.schedule.agents:
26 portrayal = self.portrayal_method(obj)
27 x, y = obj.pos
28 x = (x - model.space.x_min) / (model.space.x_max - model.space.x_min)
29 y = (y - model.space.y_min) / (model.space.y_max - model.space.y_min)
30 portrayal["x"] = x
31 portrayal["y"] = y
32 space_state.append(portrayal)
33 return space_state