Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  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. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  33. return
  34. pygame.draw.rect(self.screen, color, pygame.Rect(x * self.multiplier, y * self.multiplier, self.multiplier, self.multiplier))
  35. if __name__ == "__main__":
  36. t = TestGUI(32, 32)
  37. t.debug_loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))