Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. import time
  3. class Manager:
  4. def __init__(self, g):
  5. self.gui = g
  6. self.screens = []
  7. self.index = 0
  8. self.lastTime = time.time()
  9. def add(self, s, d = None):
  10. v = (s, d)
  11. self.screens.append(v)
  12. def loop(self):
  13. self.screens[self.index][0].draw()
  14. if self.screens[self.index][1] == None:
  15. if self.screens[self.index][0].finished():
  16. self.index = (self.index + 1) % len(self.screens)
  17. self.lastTime = time.time()
  18. self.screens[self.index][0].restart()
  19. else:
  20. # use given timeout
  21. if (time.time() - self.lastTime) > self.screens[self.index][1]:
  22. self.index = (self.index + 1) % len(self.screens)
  23. self.lastTime = time.time()
  24. self.screens[self.index][0].restart()
  25. if __name__ == "__main__":
  26. from splash import SplashScreen
  27. #from weather import WeatherScreen
  28. from draw import ScrollText
  29. from solid import Solid
  30. from life import GameOfLife
  31. import platform
  32. t = None
  33. if platform.machine() == "armv7l":
  34. from pi import PiMatrix
  35. t = PiMatrix()
  36. else:
  37. from test import TestGUI
  38. t = TestGUI()
  39. m = Manager(t)
  40. m.add(SplashScreen(t), 2)
  41. m.add(Solid(t, 1.0))
  42. #m.add(WeatherScreen(t), 4)
  43. #m.add(Solid(t, 1.0))
  44. m.add(ScrollText(t, "This appears once"))
  45. m.add(Solid(t, 1.0))
  46. m.add(ScrollText(t, "And this twice...", 2))
  47. m.add(Solid(t, 1.0))
  48. m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0))
  49. m.add(Solid(t, 1.0))
  50. t.debug_loop(m.loop)