Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. # Uses the pygame SDL wrapper:
  3. # https://github.com/pygame/pygame
  4. #
  5. # ----------------------------------------------------------------------------
  6. # "THE BEER-WARE LICENSE" (Revision 42):
  7. # <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  8. # you can do whatever you want with this stuff. If we meet some day, and you
  9. # think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  10. # ----------------------------------------------------------------------------
  11. import pygame
  12. class TestGUI:
  13. def __init__(self, width = 32 * 2, height = 32 * 2, multiplier = 16):
  14. self.width = width
  15. self.height = height
  16. self.multiplier = multiplier
  17. # compatibility to PiMatrix
  18. self.panelW = 32
  19. self.panelH = 32
  20. pygame.display.init()
  21. self.screen = pygame.display.set_mode((self.width * self.multiplier, self.height * self.multiplier))
  22. self.clock = pygame.time.Clock()
  23. self.running = True
  24. def exit(self):
  25. pygame.quit()
  26. def loop_start(self):
  27. for event in pygame.event.get():
  28. if event.type == pygame.QUIT:
  29. return True
  30. elif event.type == pygame.KEYUP:
  31. if (event.key == pygame.K_q) or (event.key == pygame.K_ESCAPE):
  32. return True
  33. self.screen.fill("black")
  34. return False
  35. def loop_end(self):
  36. pygame.display.flip()
  37. self.clock.tick(30)
  38. def set_pixel(self, x, y, color):
  39. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  40. return
  41. pygame.draw.rect(self.screen, color, pygame.Rect(x * self.multiplier, y * self.multiplier, self.multiplier, self.multiplier))
  42. if __name__ == "__main__":
  43. t = TestGUI(32, 32)
  44. util.loop(t, lambda: t.set_pixel(15, 15, (255, 255, 255)))