Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 6ce0b12

Browse files
committed
Merge branch 'snake' of https://github.com/tostadora/hyperion
2 parents cdd121f + a00b1c8 commit 6ce0b12

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

effects/snake.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name" : "Snake",
3+
"script" : "snake.py",
4+
"args" :
5+
{
6+
"rotation-time" : 10.0,
7+
"color" : [255, 0, 0],
8+
"percentage" : 25
9+
}
10+
}

effects/snake.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import hyperion
2+
import time
3+
import colorsys
4+
5+
# Get the parameters
6+
rotationTime = float(hyperion.args.get('rotation-time', 10.0))
7+
color = hyperion.args.get('color', (255,0,0))
8+
percentage = int(hyperion.args.get('percentage', 10))
9+
10+
# Check parameters
11+
rotationTime = max(0.1, rotationTime)
12+
percentage = max(1, min(percentage, 100))
13+
14+
# Process parameters
15+
factor = percentage/100.0
16+
hsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
17+
18+
# Initialize the led data
19+
snakeLeds = max(1, int(hyperion.ledCount*factor))
20+
ledData = bytearray()
21+
22+
for i in range(hyperion.ledCount-snakeLeds):
23+
ledData += bytearray((0, 0, 0))
24+
25+
for i in range(1,snakeLeds+1):
26+
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/i)
27+
ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)))
28+
29+
# Calculate the sleep time and rotation increment
30+
increment = 3
31+
sleepTime = rotationTime / hyperion.ledCount
32+
while sleepTime < 0.05:
33+
increment *= 2
34+
sleepTime *= 2
35+
increment %= hyperion.ledCount
36+
37+
# Start the write data loop
38+
while not hyperion.abort():
39+
hyperion.setColor(ledData)
40+
ledData = ledData[increment:] + ledData[:increment]
41+
time.sleep(sleepTime)

0 commit comments

Comments
 (0)