Coverage for src/scicom/randomletters/SimpleContinuousModule.py: 0%

1 import mesa

2

3

4 class 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

10

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 + ");"

22

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