Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

manager.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 scroll import ScrollText
  44. from solid import Solid
  45. from life import GameOfLife
  46. import util
  47. t = util.getTarget()
  48. splash = SplashScreen(t)
  49. t.loop_start()
  50. splash.draw()
  51. t.loop_end()
  52. m = Manager(t)
  53. m.add(ScrollText(t, "This appears once", "ib8x8u"))
  54. m.add(Solid(t, 1.0))
  55. m.add(ScrollText(t, "And this twice...", "ib8x8u", 2))
  56. m.add(Solid(t, 1.0))
  57. m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0, True))
  58. m.add(Solid(t, 1.0))
  59. sub = Manager(t)
  60. sub.add(ScrollText(t, "Hello", "ib8x8u"))
  61. sub.add(Solid(t, 1.0, (0, 255, 0)))
  62. sub.add(ScrollText(t, "World", "ib8x8u"))
  63. sub.add(Solid(t, 1.0, (0, 0, 255)))
  64. m.add(sub)
  65. m.add(Solid(t, 1.0))
  66. m.restart()
  67. t.loop(m.draw)