From 750f1100a6cc9a93838af717bb5b893740e067c7 Mon Sep 17 00:00:00 2001 From: topsinoty Date: Fri, 2 Jan 2026 02:36:11 +0200 Subject: [PATCH] refactor: read the code and remake to match DiskoPidu --- pyleds/program/promise/ChristmasLights.py | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pyleds/program/promise/ChristmasLights.py b/pyleds/program/promise/ChristmasLights.py index e0b44f6..b56bfce 100644 --- a/pyleds/program/promise/ChristmasLights.py +++ b/pyleds/program/promise/ChristmasLights.py @@ -6,33 +6,33 @@ def name(): return 'Christmas Lights' class ChristmasLights(Program): - def run(self, args: [] = None): - # Configuration - wait_ms = 0 # Speed of the animation - # Define classic festive colors + def christmas_pattern(self, offset, segment_length=2): RED = Color(255, 0, 0) GREEN = Color(0, 255, 0) - WARM_WHITE = Color(200, 180, 60) # A golden-ish warm white - + WARM_WHITE = Color(200, 180, 60) colors = [RED, GREEN, WARM_WHITE] - # This determines how many pixels of the same color are next to each other - group_size = 2 + totalLength = self._lm.count_pixels() - offset = 0 - while self.get_loop().status(): - num_pixels = self._lm.count_pixels() + for i in range(totalLength): + color_index = ((i + offset) // segment_length) % len(colors) + self._lm.set_pixel_color(i, colors[color_index]) - for i in range(num_pixels): - # Calculate which color index to use based on pixel position and current offset - # This creates the "moving" effect - color_index = ((i + offset) // group_size) % len(colors) - self._lm.set_pixel_color(i, colors[color_index]) + self._lm.show() + return len(colors) * segment_length - self._lm.show() + def run(self, args=None): + # Fsr the application in the run file is different from + # the configuration in the Program and ProgramLoading files + loop = args.get("loop", False) if args else False - # Increment offset to move the lights - offset = (offset + 1) % (len(colors) * group_size) + offset = 0 + segment_length = 2 + while self.get_loop().status(): self._lm.get_tempo().wait() - time.sleep(wait_ms / 1000.0) + cycle_limit = self.christmas_pattern(offset, segment_length) + offset = (offset + 1) % cycle_limit + + if not loop: + break