Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. import pygame
  3. class TestGUI:
  4. def __init__(self, width = 32, height = 32, multiplier = 16):
  5. self.width = width
  6. self.height = height
  7. self.multiplier = multiplier
  8. pygame.display.init()
  9. self.screen = pygame.display.set_mode((self.width * self.multiplier, self.height * self.multiplier))
  10. self.clock = pygame.time.Clock()
  11. self.running = True
  12. def exit(self):
  13. pygame.quit()
  14. def loop_start(self):
  15. for event in pygame.event.get():
  16. if event.type == pygame.QUIT:
  17. return True
  18. self.screen.fill("black")
  19. return False
  20. def loop_end(self):
  21. pygame.display.flip()
  22. self.clock.tick(60)
  23. def debug_loop(self, func = None):
  24. while True:
  25. if self.loop_start():
  26. break
  27. if func != None:
  28. func()
  29. self.loop_end()
  30. self.exit()
  31. def set_pixel(self, x, y, color):
  32. pygame.draw.rect(self.screen, color, pygame.Rect(x * self.multiplier, y * self.multiplier, self.multiplier, self.multiplier))
  33. if __name__ == "__main__":
  34. t = TestGUI(32, 32)
  35. t.debug_loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))