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.

manager.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.restart()
  9. def restart(self):
  10. self.lastTime = time.time()
  11. def add(self, s, d = None):
  12. v = (s, d)
  13. self.screens.append(v)
  14. def loop(self):
  15. self.screens[self.index][0].draw()
  16. if self.screens[self.index][1] == None:
  17. # let screen decide when it is done
  18. if self.screens[self.index][0].finished():
  19. self.lastTime = time.time()
  20. self.index = (self.index + 1) % len(self.screens)
  21. self.screens[self.index][0].restart()
  22. else:
  23. # use given timeout
  24. if (time.time() - self.lastTime) > self.screens[self.index][1]:
  25. self.lastTime = time.time()
  26. self.index = (self.index + 1) % len(self.screens)
  27. self.screens[self.index][0].restart()
  28. if __name__ == "__main__":
  29. from splash import SplashScreen
  30. from draw import ScrollText
  31. from solid import Solid
  32. from life import GameOfLife
  33. import platform
  34. t = None
  35. if platform.machine() == "armv7l":
  36. from pi import PiMatrix
  37. t = PiMatrix()
  38. else:
  39. from test import TestGUI
  40. t = TestGUI()
  41. m = Manager(t)
  42. m.add(SplashScreen(t), 2)
  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. m.restart()
  51. t.debug_loop(m.loop)