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.

scroll.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python3
  2. # Uses the Python BDF format bitmap font parser:
  3. # https://github.com/tomchen/bdfparser
  4. #
  5. # And the pillow Python Imaging Library:
  6. # https://github.com/python-pillow/Pillow
  7. #
  8. # ----------------------------------------------------------------------------
  9. # "THE BEER-WARE LICENSE" (Revision 42):
  10. # <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  11. # you can do whatever you want with this stuff. If we meet some day, and you
  12. # think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  13. # ----------------------------------------------------------------------------
  14. import os
  15. import time
  16. import util
  17. class ScrollText:
  18. def __init__(self, g, t, f, i = 1, s = 75, fg = (255, 255, 255), bg = (0, 0, 0)):
  19. DrawText = util.getTextDrawer()
  20. self.gui = g
  21. self.drawer = DrawText(self.gui, fg, bg)
  22. self.iterations = i
  23. self.speed = 1.0 / s
  24. self.setText(t, f)
  25. self.restart()
  26. def setText(self, t, f):
  27. self.text = t
  28. self.font = f
  29. self.width = self.drawer.text(self.text, self.font, 0, False)
  30. def restart(self):
  31. self.offset = -self.gui.width
  32. self.last = time.time()
  33. self.count = 0
  34. def finished(self):
  35. return (self.count >= self.iterations)
  36. def draw(self):
  37. now = time.time()
  38. if (now - self.last) > self.speed:
  39. off = (now - self.last) / self.speed
  40. self.offset += int(off)
  41. self.last = now
  42. if self.offset >= self.width:
  43. self.offset = -self.gui.width
  44. self.count += 1
  45. self.drawer.text(self.text, self.font, self.offset, True)
  46. if __name__ == "__main__":
  47. import util
  48. t = util.getTarget()
  49. # show splash screen while initializing
  50. from splash import SplashScreen
  51. splash = SplashScreen(t)
  52. t.loop_start()
  53. splash.draw()
  54. t.loop_end()
  55. from manager import Manager
  56. m = Manager(t)
  57. scriptDir = os.path.dirname(os.path.realpath(__file__))
  58. fontDir = os.path.join(scriptDir, "fonts")
  59. for f in os.listdir(os.fsencode(fontDir)):
  60. filename = os.fsdecode(f)
  61. if not filename.endswith(".bdf"):
  62. continue
  63. fontName = filename[:-4]
  64. s = fontName + " Abcdefgh " + fontName
  65. m.add(ScrollText(t, s, fontName, 1, 75, (0, 255, 0), (0, 0, 25)))
  66. m.restart()
  67. util.loop(t, m.draw)