Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

solid.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 time
  9. class Solid:
  10. def __init__(self, g, t = 1.0, c = (0, 0, 0)):
  11. self.gui = g
  12. self.time = t
  13. self.setColor(c)
  14. self.restart()
  15. def setColor(self, c):
  16. self.color = c
  17. def restart(self):
  18. self.start = time.time()
  19. def finished(self):
  20. return (time.time() - self.start) >= self.time
  21. def draw(self):
  22. for x in range(0, self.gui.width):
  23. for y in range(0, self.gui.height):
  24. self.gui.set_pixel(x, y, self.color)
  25. if __name__ == "__main__":
  26. import util
  27. t = util.getTarget()
  28. colors = [
  29. (251, 72, 196), # camp23 pink
  30. (63, 255, 33), # camp23 green
  31. (255, 0, 0),
  32. (0, 255, 0),
  33. (0, 0, 255),
  34. (255, 255, 0),
  35. (0, 255, 255),
  36. (255, 0, 255),
  37. (255, 255, 255),
  38. ]
  39. ci = 0
  40. d = Solid(t, 1.0, colors[ci])
  41. s = time.time()
  42. def helper():
  43. global s, colors, ci
  44. if (time.time() - s) >= 1.0:
  45. s = time.time()
  46. ci = (ci + 1) % len(colors)
  47. c = colors[ci]
  48. d.setColor(c)
  49. d.draw()
  50. t.loop(helper)