Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

test.py 1.7KB

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