5 Commits

Author SHA1 Message Date
topsinoty
750f1100a6 refactor: read the code and remake to match DiskoPidu 2026-01-02 02:36:11 +02:00
topsinoty
ffa77db057 use _lm.tempo and set sleep to 0 2025-12-21 16:10:41 +02:00
topsinoty
a71201d90a change to pascal case. 2025-12-21 16:01:37 +02:00
topsinoty
d811b853a1 change lib source to module 2025-12-21 15:54:53 +02:00
topsinoty
6d9c4b2f33 add generated christmas lights 2025-12-21 15:31:39 +02:00
2 changed files with 38 additions and 35 deletions

View File

@@ -0,0 +1,38 @@
from lib.Program import Program
from rpi_ws281x import Color
import time
def name():
return 'Christmas Lights'
class ChristmasLights(Program):
def christmas_pattern(self, offset, segment_length=2):
RED = Color(255, 0, 0)
GREEN = Color(0, 255, 0)
WARM_WHITE = Color(200, 180, 60)
colors = [RED, GREEN, WARM_WHITE]
totalLength = 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])
self._lm.show()
return len(colors) * segment_length
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
offset = 0
segment_length = 2
while self.get_loop().status():
self._lm.get_tempo().wait()
cycle_limit = self.christmas_pattern(offset, segment_length)
offset = (offset + 1) % cycle_limit
if not loop:
break

View File

@@ -1,35 +0,0 @@
from lib.Program import Program
from rpi_ws281x import Color
import time
def name():
return 'Vikermasetsus'
def wheel(pos):
"""Generate rainbow colors across 0-255 positions."""
if pos < 85:
return Color(pos * 3, 255 - pos * 3, 0)
elif pos < 170:
pos -= 85
return Color(255 - pos * 3, 0, pos * 3)
else:
pos -= 170
return Color(0, pos * 3, 255 - pos * 3)
class Vikermasetsus(Program):
def run(self, args: [] = None):
wait_ms = 20
iterations = 5
while self.get_loop().status():
"""Draw rainbow that uniformly distributes itself across all pixels."""
for j in range(256 * iterations):
if not self.get_loop().status():
break
for i in range(self._lm.count_pixels()):
self._lm.set_pixel_color(i, wheel(
(int(i * 2560 / self._lm.count_pixels()) + j) & 255))
self._lm.show()
time.sleep(wait_ms / 1000.0)