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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. print(self.text, self.font, self.width)
  31. def restart(self):
  32. self.offset = -self.gui.width
  33. self.last = time.time()
  34. self.count = 0
  35. def finished(self):
  36. return (self.count >= self.iterations)
  37. def draw(self):
  38. if (time.time() - self.last) > self.speed:
  39. off = (time.time() - self.last) / self.speed
  40. print(self.offset, "->", self.offset + int(off))
  41. self.offset += int(off)
  42. self.last = time.time()
  43. if self.offset >= self.width:
  44. self.offset = -self.gui.width
  45. self.count += 1
  46. self.drawer.text(self.text, self.font, self.offset, True)
  47. if __name__ == "__main__":
  48. import util
  49. t = util.getTarget()
  50. # show splash screen while initializing
  51. from splash import SplashScreen
  52. splash = SplashScreen(t)
  53. t.loop_start()
  54. splash.draw()
  55. t.loop_end()
  56. from manager import Manager
  57. m = Manager(t)
  58. scriptDir = os.path.dirname(os.path.realpath(__file__))
  59. fontDir = os.path.join(scriptDir, "fonts")
  60. for f in os.listdir(os.fsencode(fontDir)):
  61. filename = os.fsdecode(f)
  62. if not filename.endswith(".bdf"):
  63. continue
  64. fontName = filename[:-4]
  65. s = fontName + " Abcdefgh " + fontName
  66. m.add(ScrollText(t, s, fontName, 1, 75, (0, 255, 0), (0, 0, 25)))
  67. m.restart()
  68. t.loop(m.draw)