Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. now = time.time()
  21. return ((now - self.start) >= self.time) or (now < self.start)
  22. def draw(self):
  23. for x in range(0, self.gui.width):
  24. for y in range(0, self.gui.height):
  25. self.gui.set_pixel(x, y, self.color)
  26. if __name__ == "__main__":
  27. import util
  28. t = util.getTarget()
  29. d = Solid(t, 1.0, (0, 0, 0))
  30. colors = [
  31. (251, 72, 196), # camp23 pink
  32. (63, 255, 33), # camp23 green
  33. (255, 0, 0),
  34. (0, 255, 0),
  35. (0, 0, 255),
  36. (255, 255, 0),
  37. (0, 255, 255),
  38. (255, 0, 255),
  39. (255, 255, 255),
  40. ]
  41. s = time.time()
  42. ci = 0
  43. n = 0
  44. c = (0, 0, 0)
  45. def helper():
  46. global s, colors, ci, n, c
  47. now = time.time()
  48. if ((now - s) >= 0.5) or (now < s):
  49. s = now
  50. n += 1
  51. if n >= 15:
  52. ci = (ci + 1) % len(colors)
  53. n = 0
  54. c = (0, 0, 0)
  55. elif n <= 10:
  56. c = colors[ci]
  57. c = (int(c[0] * (0.1 * n)), int(c[1] * (0.1 * n)), int(c[2] * (0.1 * n)))
  58. d.setColor(c)
  59. d.draw()
  60. util.loop(t, helper)