Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

solid.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. d = Solid(t, 1.0, (0, 0, 0))
  29. colors = [
  30. (251, 72, 196), # camp23 pink
  31. (63, 255, 33), # camp23 green
  32. (255, 0, 0),
  33. (0, 255, 0),
  34. (0, 0, 255),
  35. (255, 255, 0),
  36. (0, 255, 255),
  37. (255, 0, 255),
  38. (255, 255, 255),
  39. ]
  40. s = time.time()
  41. ci = 0
  42. n = 0
  43. c = (0, 0, 0)
  44. def helper():
  45. global s, colors, ci, n, c
  46. if (time.time() - s) >= 0.1:
  47. s = time.time()
  48. n += 1
  49. if n >= 15:
  50. ci = (ci + 1) % len(colors)
  51. n = 0
  52. c = (0, 0, 0)
  53. elif n <= 10:
  54. c = colors[ci]
  55. c = (int(c[0] * (0.1 * n)), int(c[1] * (0.1 * n)), int(c[2] * (0.1 * n)))
  56. d.setColor(c)
  57. d.draw()
  58. t.loop(helper)