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

Class FadingText

PythonAPI/examples/manual_control_steeringwheel.py:519–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517
518
519class FadingText(object):
520 def __init__(self, font, dim, pos):
521 self.font = font
522 self.dim = dim
523 self.pos = pos
524 self.seconds_left = 0
525 self.surface = pygame.Surface(self.dim)
526
527 def set_text(self, text, color=(255, 255, 255), seconds=2.0):
528 text_texture = self.font.render(text, True, color)
529 self.surface = pygame.Surface(self.dim)
530 self.seconds_left = seconds
531 self.surface.fill((0, 0, 0, 0))
532 self.surface.blit(text_texture, (10, 11))
533
534 def tick(self, _, clock):
535 delta_seconds = 1e-3 * clock.get_time()
536 self.seconds_left = max(0.0, self.seconds_left - delta_seconds)
537 self.surface.set_alpha(500.0 * self.seconds_left)
538
539 def render(self, display):
540 display.blit(self.surface, self.pos)
541
542
543# ==============================================================================

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected