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

test.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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, height = 32, multiplier = 16):
  14. self.width = width
  15. self.height = height
  16. self.multiplier = multiplier
  17. pygame.display.init()
  18. self.screen = pygame.display.set_mode((self.width * self.multiplier, self.height * self.multiplier))
  19. self.clock = pygame.time.Clock()
  20. self.running = True
  21. def exit(self):
  22. pygame.quit()
  23. def loop_start(self):
  24. for event in pygame.event.get():
  25. if event.type == pygame.QUIT:
  26. return True
  27. elif event.type == pygame.KEYUP:
  28. if (event.key == pygame.K_q) or (event.key == pygame.K_ESCAPE):
  29. return True
  30. self.screen.fill("black")
  31. return False
  32. def loop_end(self):
  33. pygame.display.flip()
  34. self.clock.tick(30)
  35. def debug_loop(self, func = None):
  36. while True:
  37. if self.loop_start():
  38. break
  39. if func != None:
  40. func()
  41. self.loop_end()
  42. self.exit()
  43. def set_pixel(self, x, y, color):
  44. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  45. return
  46. pygame.draw.rect(self.screen, color, pygame.Rect(x * self.multiplier, y * self.multiplier, self.multiplier, self.multiplier))
  47. if __name__ == "__main__":
  48. t = TestGUI(32, 32)
  49. t.debug_loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))