Compare commits

..

1 Commits

Author SHA1 Message Date
Pearu Vaalma 545ff966c8 add generated christmas lights (#9) 2 weeks ago
  1. 40
      pyleds/program/promise/ChristmasLights.py

@ -6,33 +6,33 @@ def name():
return 'Christmas Lights' return 'Christmas Lights'
class ChristmasLights(Program): class ChristmasLights(Program):
def run(self, args: [] = None):
# Configuration
wait_ms = 0 # Speed of the animation
def christmas_pattern(self, offset, segment_length=2): # Define classic festive colors
RED = Color(255, 0, 0) RED = Color(255, 0, 0)
GREEN = Color(0, 255, 0) GREEN = Color(0, 255, 0)
WARM_WHITE = Color(200, 180, 60) WARM_WHITE = Color(200, 180, 60) # A golden-ish warm white
colors = [RED, GREEN, WARM_WHITE] colors = [RED, GREEN, WARM_WHITE]
totalLength = self._lm.count_pixels() # This determines how many pixels of the same color are next to each other
group_size = 2
for i in range(totalLength): offset = 0
color_index = ((i + offset) // segment_length) % len(colors) while self.get_loop().status():
self._lm.set_pixel_color(i, colors[color_index]) num_pixels = self._lm.count_pixels()
self._lm.show() for i in range(num_pixels):
return len(colors) * segment_length # 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])
def run(self, args=None): self._lm.show()
# 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
offset = 0 # Increment offset to move the lights
segment_length = 2 offset = (offset + 1) % (len(colors) * group_size)
while self.get_loop().status():
self._lm.get_tempo().wait() self._lm.get_tempo().wait()
cycle_limit = self.christmas_pattern(offset, segment_length) time.sleep(wait_ms / 1000.0)
offset = (offset + 1) % cycle_limit
if not loop:
break

Loading…
Cancel
Save