Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

manager.py 2.1KB

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 Manager:
  10. def __init__(self, g):
  11. self.gui = g
  12. self.screens = []
  13. self.index = 0
  14. self.restart()
  15. def restart(self):
  16. self.lastTime = time.time()
  17. def add(self, s, d = None):
  18. v = (s, d)
  19. self.screens.append(v)
  20. def loop(self):
  21. self.screens[self.index][0].draw()
  22. if self.screens[self.index][1] == None:
  23. # let screen decide when it is done
  24. if self.screens[self.index][0].finished():
  25. self.lastTime = time.time()
  26. self.index = (self.index + 1) % len(self.screens)
  27. self.screens[self.index][0].restart()
  28. else:
  29. # use given timeout
  30. if (time.time() - self.lastTime) > self.screens[self.index][1]:
  31. self.lastTime = time.time()
  32. self.index = (self.index + 1) % len(self.screens)
  33. self.screens[self.index][0].restart()
  34. if __name__ == "__main__":
  35. from splash import SplashScreen
  36. from draw import ScrollText
  37. from solid import Solid
  38. from life import GameOfLife
  39. import platform
  40. t = None
  41. if platform.machine() == "armv7l":
  42. from pi import PiMatrix
  43. t = PiMatrix()
  44. else:
  45. from test import TestGUI
  46. t = TestGUI()
  47. m = Manager(t)
  48. m.add(SplashScreen(t), 2)
  49. m.add(Solid(t, 1.0))
  50. m.add(ScrollText(t, "This appears once"))
  51. m.add(Solid(t, 1.0))
  52. m.add(ScrollText(t, "And this twice...", 2))
  53. m.add(Solid(t, 1.0))
  54. m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0))
  55. m.add(Solid(t, 1.0))
  56. m.restart()
  57. t.debug_loop(m.loop)