MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / _render_speed_limits

Method _render_speed_limits

PythonAPI/examples/no_rendering_mode.py:1160–1195  ·  view source on GitHub ↗

Renders the speed limits by drawing two concentric circles (outer is red and inner white) and a speed limit text

(self, surface, list_sl, world_to_pixel, world_to_pixel_width)

Source from the content-addressed store, hash-verified

1158 surface.blit(srf, srf.get_rect(center=pos))
1159
1160 def _render_speed_limits(self, surface, list_sl, world_to_pixel, world_to_pixel_width):
1161 """Renders the speed limits by drawing two concentric circles (outer is red and inner white) and a speed limit text"""
1162
1163 font_size = world_to_pixel_width(2)
1164 radius = world_to_pixel_width(2)
1165 font = pygame.font.SysFont('Arial', font_size)
1166
1167 for sl in list_sl:
1168
1169 x, y = world_to_pixel(sl.get_location())
1170
1171 # Render speed limit concentric circles
1172 white_circle_radius = int(radius * 0.75)
1173
1174 pygame.draw.circle(surface, COLOR_SCARLET_RED_1, (x, y), radius)
1175 pygame.draw.circle(surface, COLOR_ALUMINIUM_0, (x, y), white_circle_radius)
1176
1177 limit = sl.type_id.split('.')[2]
1178 font_surface = font.render(limit, True, COLOR_ALUMINIUM_5)
1179
1180 if self.args.show_triggers:
1181 corners = Util.get_bounding_box(sl)
1182 corners = [world_to_pixel(p) for p in corners]
1183 pygame.draw.lines(surface, COLOR_PLUM_2, True, corners, 2)
1184
1185 # Blit
1186 if self.hero_actor is not None:
1187 # In hero mode, Rotate font surface with respect to hero vehicle front
1188 angle = -self.hero_transform.rotation.yaw - 90.0
1189 font_surface = pygame.transform.rotate(font_surface, angle)
1190 offset = font_surface.get_rect(center=(x, y))
1191 surface.blit(font_surface, offset)
1192
1193 else:
1194 # In map mode, there is no need to rotate the text of the speed limit
1195 surface.blit(font_surface, (x - radius / 2, y - radius / 2))
1196
1197 def _render_walkers(self, surface, list_w, world_to_pixel):
1198 """Renders the walkers' bounding boxes"""

Callers 1

render_actorsMethod · 0.95

Calls 3

rotateMethod · 0.80
renderMethod · 0.45
get_bounding_boxMethod · 0.45

Tested by

no test coverage detected