Coverage for .tox/p311/lib/python3.11/site-packages/scicom/randomletters/SimpleContinuousModule.py: 0%

24 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-17 13:30 +0200

1import mesa 

2 

3 

4class SimpleCanvas(mesa.visualization.VisualizationElement): 

5 """Display agents on a map background. No coordinates.""" 

6 local_includes = ["randomletters/simple_continuous_canvas.js"] 

7 local_css_includes = ["randomletters/map.png"] 

8 portrayal_method = None 

9 canvas_height = 720 

10 canvas_width = 1280 

11 

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

13 """ 

14 Instantiate a new SimpleCanvas 

15 """ 

16 self.portrayal_method = portrayal_method 

17 self.canvas_height = canvas_height 

18 self.canvas_width = canvas_width 

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

20 self.canvas_width, self.canvas_height 

21 ) 

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

23 

24 def render(self, model): 

25 """How to render the agents""" 

26 space_state = [] 

27 for obj in model.schedule.agents: 

28 portrayal = self.portrayal_method(obj) 

29 x, y = obj.pos 

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

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

32 portrayal["x"] = x 

33 portrayal["y"] = y 

34 space_state.append(portrayal) 

35 return space_state