From 29b4d65380cba1ad7716eae8f97b12c1868cab48 Mon Sep 17 00:00:00 2001 From: Kariiv Date: Tue, 24 Nov 2020 23:52:13 +0200 Subject: [PATCH] Hehe Tehtud, veel mitte. --- pyleds/lib/FakeStrip.py | 49 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/pyleds/lib/FakeStrip.py b/pyleds/lib/FakeStrip.py index ad20338..9c9ef27 100644 --- a/pyleds/lib/FakeStrip.py +++ b/pyleds/lib/FakeStrip.py @@ -1,5 +1,7 @@ from rpi_ws281x import PixelStrip import atexit +from tkinter import Tk, Canvas +from threading import Thread class _LedData(object): @@ -63,6 +65,15 @@ class FakeStrip(PixelStrip): # Substitute for __del__, traps an exit condition and cleans up properly atexit.register(self._cleanup) + self.viz = Tk() + self.x = 1000 + self.y = 500 + self.viz.geometry(f'{self.x}x{self.y}') + self.canv = Canvas(self.viz) + self.canv.pack(expand=1) + self.th.start() + self.th = Thread(target=self.viz.mainloop) + def _cleanup(self): # Clean up memory used by the library when not needed anymore. if self._channel is not None: @@ -78,7 +89,43 @@ class FakeStrip(PixelStrip): def show(self): """Update the display with the data from the LED buffer.""" - return # render + self.canv.delete("all") + size = 10.5 + bp = [47, 97, 191, 242, 289] + for s in range(self.numPixels()): + x1 = 0 + y1 = 0 + x2 = 0 + y2 = 0 + + if s < bp[0]: + x1 = (self.x / 2) + s * size + y1 = 0 + x2 = x1 + size + y2 = size + elif s < bp[1]: + x1 = self.x - size + y1 = -(bp[0] - s) * size + x2 = x1 + size + y2 = y1 + size + elif s < bp[2]: + x1 = self.x + (bp[1] - s) * size + y1 = self.y + x2 = x1 - size + y2 = y1 - size + elif s < bp[3]: + x1 = 0 + y1 = self.y + (bp[2] - s) * size + x2 = x1 + size + y2 = y1 - size + elif s < bp[4]: + x1 = size * - (bp[3] - s) + y1 = 0 + x2 = x1 + size + y2 = y1 + size + + rgb = self.getPixelColorRGB(s) + self.canv.create_rectangle(x1, y1, x2, y2, fill="#%02x%02x%02x" % (rgb.r, rgb.g, rgb.b)) def getBrightness(self) -> int: return self._brightness