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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env python3
  2. # For the Pimoroni Interstate75 Raspberry Pi Pico RGB LED Matrix interface:
  3. # https://github.com/pimoroni/pimoroni-pico
  4. #
  5. # ----------------------------------------------------------------------------
  6. # "THE BEER-WARE LICENSE" (Revision 42):
  7. # <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  8. # you can do whatever you want with this stuff. If we meet some day, and you
  9. # think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  10. # ----------------------------------------------------------------------------
  11. import interstate75
  12. class PicoMatrix:
  13. def __init__(self, w = 32, h = 32):
  14. self.width = w # x-axis
  15. self.height = h # y-axis
  16. self.panelW = w # x-axis
  17. self.panelH = h # y-axis
  18. # compatibility to TestGUI
  19. self.multiplier = 1.0
  20. if (w != 32) or (h != 32):
  21. raise RuntimeError("TODO not yet supported")
  22. self.matrix = interstate75.Interstate75(display = interstate75.DISPLAY_INTERSTATE75_32X32)
  23. self.black = self.matrix.display.create_pen(0, 0, 0)
  24. self.white = self.matrix.display.create_pen(255, 255, 255)
  25. self.loop_start() # initialize with blank image for ScrollText constructor
  26. def loop_start(self):
  27. self.matrix.display.set_pen(self.black)
  28. self.matrix.display.clear()
  29. self.matrix.display.set_pen(self.white)
  30. return False # no input, never quit on our own
  31. def loop_end(self):
  32. self.matrix.update()
  33. def loop(self, func = None):
  34. while True:
  35. if self.loop_start():
  36. break
  37. if func != None:
  38. func()
  39. self.loop_end()
  40. self.matrix.stop()
  41. def set_pixel(self, x, y, color):
  42. if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
  43. return
  44. pen = self.matrix.display.create_pen(color[0], color[1], color[2])
  45. self.matrix.display.set_pen(pen)
  46. self.matrix.display.pixel(int(x), int(y))
  47. class PicoText:
  48. def __init__(self, g, fg = (255, 255, 255), bg = (0, 0, 0), c = (0, 255, 0)):
  49. self.gui = g
  50. self.fg = fg
  51. self.bg = bg
  52. self.color = c
  53. def text(self, s, f, offset = 0, earlyAbort = True, yOff = 0, compat = True):
  54. pen = self.gui.matrix.display.create_pen(self.fg[0], self.fg[1], self.fg[2])
  55. self.gui.matrix.display.set_pen(pen)
  56. self.gui.matrix.display.set_font(f)
  57. if not compat:
  58. x = 0
  59. y = yOff
  60. else:
  61. # TODO
  62. x = 0
  63. y = int(self.gui.height / 2 - 4 + yOff)
  64. self.gui.matrix.display.text(s, x, y, scale=1)
  65. if __name__ == "__main__":
  66. import time
  67. t = PicoMatrix(32, 32)
  68. s = PicoText(t)
  69. start = time.time()
  70. i = 0
  71. def helper():
  72. global s, start, i
  73. if (time.time() - start) > 2.0:
  74. start = time.time()
  75. i = (i + 1) % 2
  76. if i == 0:
  77. s.text("Abgj6", "bitmap6", 0, True, 0, False)
  78. s.text("Abdgj8", "bitmap8", 0, True, 6 + 2, False)
  79. s.text("Ag14", "bitmap14_outline", 0, True, 6 + 2 + 8 + 1, False)
  80. else:
  81. s.text("Drinks:", "bitmap8", 0)
  82. t.loop(helper)