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.

mapper.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. # Does nothing. Take this as parent for new mappers.
  9. class MapperNull:
  10. def __init__(self, g):
  11. self.gui = g
  12. self.width = self.gui.width
  13. self.height = self.gui.height
  14. self.multiplier = self.gui.multiplier
  15. self.panelW = self.gui.panelW
  16. self.panelH = self.gui.panelH
  17. def loop_start(self):
  18. return self.gui.loop_start()
  19. def loop_end(self):
  20. self.gui.loop_end()
  21. def loop(self, func = None):
  22. self.gui.loop(func)
  23. def set_pixel(self, x, y, color):
  24. self.gui.set_pixel(x, y, color)
  25. # For some reason the red and green LEDs on older Pimoroni panels
  26. # are far brighter than on newer panels.
  27. # Adjust this by multiplying rg channels with 0.75, depending
  28. # on hard-corded coordinate ranges.
  29. class MapperColorAdjust(MapperNull):
  30. def set_pixel(self, x, y, color):
  31. # third panel from the left, with 64 <= x < 96,
  32. # is "old" type with brighter LEDs.
  33. # rest of panels to the left and right are less bright.
  34. # so adjust brightness of inner panel rg channels down.
  35. if (x >= (self.gui.panelW * 2)) and (x < (self.gui.panelW * 3)):
  36. color = (int(color[0] * 0.75), int(color[1] * 0.75), color[2])
  37. self.gui.set_pixel(x, y, color)
  38. # This converts a long 128x32 strip to a 64x64 panel.
  39. # The Pi is always connected to d, the last subpanel.
  40. #
  41. # (0, 0) (128, 0)
  42. # a b c d
  43. # (0, 32) (128, 32)
  44. #
  45. # on the hardware is converted to this for the effects:
  46. #
  47. # (0, 0) (64, 0)
  48. # a b
  49. # c d
  50. # (0, 64) (64, 64)
  51. class MapperStripToRect(MapperNull):
  52. def __init__(self, g):
  53. super().__init__(g)
  54. self.width = int(self.gui.width / 2)
  55. self.height = self.gui.height * 2
  56. def set_pixel(self, x, y, color):
  57. if y >= self.gui.height:
  58. x += self.width
  59. y -= self.panelH
  60. self.gui.set_pixel(x, y, color)