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 2.5KB

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