mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
new effect!
Former-commit-id: e19975e298fd6b11e7012739ac37ee3047d2c184
This commit is contained in:
parent
ff0fb78e33
commit
faee31c83f
10
effects/snake.json
Normal file
10
effects/snake.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name" : "Snake",
|
||||||
|
"script" : "snake.py",
|
||||||
|
"args" :
|
||||||
|
{
|
||||||
|
"rotation-time" : 10.0,
|
||||||
|
"color" : [255, 0, 0],
|
||||||
|
"percentage" : 25
|
||||||
|
}
|
||||||
|
}
|
39
effects/snake.py
Normal file
39
effects/snake.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import hyperion
|
||||||
|
import time
|
||||||
|
import colorsys
|
||||||
|
|
||||||
|
# Get the parameters
|
||||||
|
rotationTime = float(hyperion.args.get('rotation-time', 10.0))
|
||||||
|
color = hyperion.args.get('color', (255,0,0))
|
||||||
|
percentage = int(hyperion.args.get('percentage', 10))
|
||||||
|
|
||||||
|
# Check parameters
|
||||||
|
rotationTime = max(0.1, rotationTime)
|
||||||
|
percentage = max(1, min(percentage, 100))
|
||||||
|
|
||||||
|
# Initialize the led data
|
||||||
|
factor = float(percentage)/100.0
|
||||||
|
snakeLeds = int(hyperion.ledCount*factor)
|
||||||
|
ledData = bytearray()
|
||||||
|
|
||||||
|
for i in range(hyperion.ledCount-snakeLeds):
|
||||||
|
ledData += bytearray((0, 0, 0))
|
||||||
|
|
||||||
|
for i in range(1, snakeLeds+1):
|
||||||
|
hsv = colorsys.rgb_to_hsv(float(color[0])/float(255), float(color[1])/float(255), float(color[2])/float(255))
|
||||||
|
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/float(snakeLeds+1-i))
|
||||||
|
ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)))
|
||||||
|
|
||||||
|
# Calculate the sleep time and rotation increment
|
||||||
|
increment = 3
|
||||||
|
sleepTime = rotationTime / hyperion.ledCount
|
||||||
|
while sleepTime < 0.05:
|
||||||
|
increment *= 2
|
||||||
|
sleepTime *= 2
|
||||||
|
increment %= hyperion.ledCount
|
||||||
|
|
||||||
|
# Start the write data loop
|
||||||
|
while not hyperion.abort():
|
||||||
|
hyperion.setColor(ledData)
|
||||||
|
ledData = ledData[-increment:] + ledData[:-increment]
|
||||||
|
time.sleep(sleepTime)
|
Loading…
Reference in New Issue
Block a user