MCPcopy Create free account
hub / github.com/OpenDriveLab/DriveAdapter / TrafficLightSurfaces

Class TrafficLightSurfaces

scenario_runner/no_rendering_mode.py:396–426  ·  view source on GitHub ↗

Holds the surfaces (scaled and rotated) for painting traffic lights

Source from the content-addressed store, hash-verified

394
395
396class TrafficLightSurfaces(object):
397 """Holds the surfaces (scaled and rotated) for painting traffic lights"""
398
399 def __init__(self):
400 def make_surface(tl):
401 w = 40
402 surface = pygame.Surface((w, 3 * w), pygame.SRCALPHA)
403 surface.fill(COLOR_ALUMINIUM_5 if tl != 'h' else COLOR_ORANGE_2)
404 if tl != 'h':
405 hw = int(w / 2)
406 off = COLOR_ALUMINIUM_4
407 red = COLOR_SCARLET_RED_0
408 yellow = COLOR_BUTTER_0
409 green = COLOR_CHAMELEON_0
410 pygame.draw.circle(surface, red if tl == tls.Red else off, (hw, hw), int(0.4 * w))
411 pygame.draw.circle(surface, yellow if tl == tls.Yellow else off, (hw, w + hw), int(0.4 * w))
412 pygame.draw.circle(surface, green if tl == tls.Green else off, (hw, 2 * w + hw), int(0.4 * w))
413 return pygame.transform.smoothscale(surface, (15, 45) if tl != 'h' else (19, 49))
414 self._original_surfaces = {
415 'h': make_surface('h'),
416 tls.Red: make_surface(tls.Red),
417 tls.Yellow: make_surface(tls.Yellow),
418 tls.Green: make_surface(tls.Green),
419 tls.Off: make_surface(tls.Off),
420 tls.Unknown: make_surface(tls.Unknown)
421 }
422 self.surfaces = dict(self._original_surfaces)
423
424 def rotozoom(self, angle, scale):
425 for key, surface in self._original_surfaces.items():
426 self.surfaces[key] = pygame.transform.rotozoom(surface, angle, scale)
427
428
429# ==============================================================================

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected