forked from andreeuuetoa/litsimaja
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
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
|