Python RGB Matrix games and animations https://www.xythobuz.de/ledmatrix_v2.html
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

qr.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. import qrcode
  10. import util
  11. class QRScreen:
  12. def __init__(self, g, d, t = 10.0, c1 = (0, 0, 0), c2 = (255, 255, 255)):
  13. self.gui = g
  14. self.time = t
  15. self.c1 = c1
  16. self.c2 = c2
  17. qr = qrcode.QRCode(
  18. box_size = 1,
  19. border = 0,
  20. )
  21. qr.add_data(d)
  22. qr.make(fit = True)
  23. if util.isPi():
  24. # work-around for weird bug in old qrcode lib?
  25. self.image = qr.make_image(fill_color = "black", back_color = "white")
  26. self.c1 = (0, 0, 0)
  27. self.c2 = (255, 255, 255)
  28. else:
  29. self.image = qr.make_image(fill_color = self.c1, back_color = self.c2)
  30. self.xOff = int((self.gui.width - self.image.width) / 2)
  31. self.yOff = int((self.gui.height - self.image.height) / 2)
  32. self.restart()
  33. def restart(self):
  34. self.start = time.time()
  35. def finished(self):
  36. return (time.time() - self.start) >= self.time
  37. def draw(self):
  38. # fill border, if needed
  39. if self.c2 != (0, 0, 0):
  40. for x in range(0, self.gui.width):
  41. for y in range(0, self.yOff):
  42. self.gui.set_pixel(x, y, self.c2)
  43. for y in range(0, self.gui.height - self.image.height - self.yOff):
  44. self.gui.set_pixel(x, y + self.yOff + self.image.height, self.c2)
  45. for y in range(0, self.image.height):
  46. for x in range(0, self.xOff):
  47. self.gui.set_pixel(x, y + self.yOff, self.c2)
  48. for x in range(0, self.gui.width - self.image.width - self.xOff):
  49. self.gui.set_pixel(x + self.xOff + self.image.width, y + self.yOff, self.c2)
  50. for x in range(0, self.image.width):
  51. for y in range(0, self.image.height):
  52. v = self.image.getpixel((x, y))
  53. if isinstance(v, int):
  54. v = (v, v, v)
  55. self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
  56. if __name__ == "__main__":
  57. import util
  58. t = util.getTarget()
  59. d = QRScreen(t, "Hello World")
  60. t.debug_loop(d.draw)