Compare commits
3 Commits
feat/chris
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 308f17b03f | |||
|
|
f2e97ed465 | ||
| 545ff966c8 |
14
pyleds/program/eerik/Strips.py
Normal file
14
pyleds/program/eerik/Strips.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from lib.Program import Program
|
||||||
|
|
||||||
|
def name():
|
||||||
|
return '2-color strips'
|
||||||
|
|
||||||
|
class Strips(Program):
|
||||||
|
def run(self, args = None) -> None:
|
||||||
|
for i in range(self._lm.count_pixels()):
|
||||||
|
if i // 5 % 2:
|
||||||
|
color = (255, 255, 255)
|
||||||
|
else:
|
||||||
|
color = args['color']
|
||||||
|
self._lm.set_pixel_color(i, (color[0] << 16) | (color[1] << 8) | color[2])
|
||||||
|
self._lm.show()
|
||||||
@@ -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():
|
||||||
|
num_pixels = self._lm.count_pixels()
|
||||||
|
|
||||||
|
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.set_pixel_color(i, colors[color_index])
|
||||||
|
|
||||||
self._lm.show()
|
self._lm.show()
|
||||||
return len(colors) * segment_length
|
|
||||||
|
|
||||||
def run(self, args=None):
|
# Increment offset to move the lights
|
||||||
# Fsr the application in the run file is different from
|
offset = (offset + 1) % (len(colors) * group_size)
|
||||||
# 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()
|
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
|
|
||||||
|
|||||||
35
pyleds/program/siinus/Vikermasetsus.py
Normal file
35
pyleds/program/siinus/Vikermasetsus.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
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)
|
||||||
Reference in New Issue
Block a user