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

Commit e19975e

Browse files
committed
new effect!
1 parent 85a1139 commit e19975e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
# Initialize the led data
15+
factor = float(percentage)/100.0
16+
snakeLeds = int(hyperion.ledCount*factor)
17+
ledData = bytearray()
18+
19+
for i in range(hyperion.ledCount-snakeLeds):
20+
ledData += bytearray((0, 0, 0))
21+
22+
for i in range(1, snakeLeds+1):
23+
hsv = colorsys.rgb_to_hsv(float(color[0])/float(255), float(color[1])/float(255), float(color[2])/float(255))
24+
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/float(snakeLeds+1-i))
25+
ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)))
26+
27+
# Calculate the sleep time and rotation increment
28+
increment = 3
29+
sleepTime = rotationTime / hyperion.ledCount
30+
while sleepTime < 0.05:
31+
increment *= 2
32+
sleepTime *= 2
33+
increment %= hyperion.ledCount
34+
35+
# Start the write data loop
36+
while not hyperion.abort():
37+
hyperion.setColor(ledData)
38+
ledData = ledData[-increment:] + ledData[:-increment]
39+
time.sleep(sleepTime)

0 commit comments

Comments
 (0)