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

1 import mesa

2

3

4 class SimpleCanvas(mesa.visualization.VisualizationElement):

5 local_includes = ["knowledgespread/simple_continuous_canvas.js"]

6 portrayal_method = None

7 canvas_height = 720

8 canvas_width = 1280

9

10 def __init__(self, portrayal_method, canvas_height=720, canvas_width=1280):

11 """

12 Instantiate a new SimpleCanvas

13 """

14 self.portrayal_method = portrayal_method

15 self.canvas_height = canvas_height

16 self.canvas_width = canvas_width

17 new_element = "new Simple_Continuous_Module({}, {})".format(

18 self.canvas_width, self.canvas_height

19 )

20 self.js_code = "elements.push(" + new_element + ");"

21

22 def render(self, model):

23 space_state = []

24 for obj in model.schedule.agents:

25 portrayal = self.portrayal_method(obj)

26 x, y = obj.pos

27 x = (x - model.space.x_min) / (model.space.x_max - model.space.x_min)

28 y = (y - model.space.y_min) / (model.space.y_max - model.space.y_min)

29 portrayal["x"] = x

30 portrayal["y"] = y

31 space_state.append(portrayal)

32 return space_state