mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Use GIF files for effects (#477)
* Add new Effects * add schema file for gif based effects * add background color to snake effect * add background color to snake effect * Update schema file for snake effect * Add function getImage * add function getImage * optimize lights.gif * Add format to GIF schema
This commit is contained in:
committed by
brindosch
parent
838008568a
commit
9cc6c75633
BIN
effects/fire.gif
Normal file
BIN
effects/fire.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 KiB |
10
effects/fire.json
Normal file
10
effects/fire.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name" : "Fire",
|
||||
"script" : "gif.py",
|
||||
"args" :
|
||||
{
|
||||
"image" : ":fire.gif",
|
||||
"fps" :25,
|
||||
"reverse" : false
|
||||
}
|
||||
}
|
16
effects/gif.py
Normal file
16
effects/gif.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os, hyperion, time
|
||||
|
||||
# Get the parameters
|
||||
imageFile = hyperion.args.get('image')
|
||||
framesPerSecond = float(hyperion.args.get('fps', 25))
|
||||
reverse = bool(hyperion.args.get('reverse', False))
|
||||
|
||||
sleepTime = 1./framesPerSecond
|
||||
if imageFile:
|
||||
imageList = list(reversed(hyperion.getImage(imageFile))) if reverse else hyperion.getImage(imageFile)
|
||||
|
||||
# Start the write data loop
|
||||
while not hyperion.abort() and imageList:
|
||||
for image in imageList:
|
||||
hyperion.setImage(image.imageWidth, image.imageHeight, image.imageData)
|
||||
time.sleep(sleepTime)
|
BIN
effects/lights.gif
Normal file
BIN
effects/lights.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 229 KiB |
10
effects/lights.json
Normal file
10
effects/lights.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name" : "Lights",
|
||||
"script" : "gif.py",
|
||||
"args" :
|
||||
{
|
||||
"image" : ":lights.gif",
|
||||
"fps" :25,
|
||||
"reverse" : false
|
||||
}
|
||||
}
|
31
effects/schema/gif.schema.json
Normal file
31
effects/schema/gif.schema.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"type":"object",
|
||||
"script" : "gif.py",
|
||||
"title":"edt_eff_gif_header",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"image": {
|
||||
"type": "string",
|
||||
"title":"edt_eff_image",
|
||||
"format" : "file",
|
||||
"default": "",
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
"fps": {
|
||||
"type": "integer",
|
||||
"title":"edt_eff_fps",
|
||||
"default": 25,
|
||||
"minimum" : 1,
|
||||
"maximum" : 100,
|
||||
"step" : 1,
|
||||
"propertyOrder" : 2
|
||||
},
|
||||
"reverse": {
|
||||
"type": "boolean",
|
||||
"title":"edt_eff_reversedirection",
|
||||
"default": false,
|
||||
"propertyOrder" : 3
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@@ -18,20 +18,34 @@
|
||||
"maxItems": 3,
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
"background-color": {
|
||||
"type": "array",
|
||||
"title":"edt_eff_color",
|
||||
"format":"colorpicker",
|
||||
"default": [0,0,0],
|
||||
"items" : {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3,
|
||||
"propertyOrder" : 2
|
||||
},
|
||||
"rotation-time": {
|
||||
"type": "number",
|
||||
"title":"edt_eff_rotationtime",
|
||||
"default": 12.0,
|
||||
"minimum" : 0.1,
|
||||
"append" : "edt_append_s",
|
||||
"propertyOrder" : 2
|
||||
"propertyOrder" : 3
|
||||
},
|
||||
"percentage": {
|
||||
"type": "integer",
|
||||
"title":"edt_eff_length",
|
||||
"default": 10,
|
||||
"append" : "edt_append_percent",
|
||||
"propertyOrder" : 3
|
||||
"propertyOrder" : 4
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@@ -5,6 +5,7 @@
|
||||
{
|
||||
"rotation-time" : 12.0,
|
||||
"color" : [255, 0, 0],
|
||||
"background-color" : [0, 0, 0],
|
||||
"percentage" : 10
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import colorsys
|
||||
# Get the parameters
|
||||
rotationTime = float(hyperion.args.get('rotation-time', 10.0))
|
||||
color = hyperion.args.get('color', (255,0,0))
|
||||
backgroundColor = hyperion.args.get('background-color', (0,0,0))
|
||||
percentage = int(hyperion.args.get('percentage', 10))
|
||||
|
||||
# Check parameters
|
||||
@@ -13,17 +14,23 @@ percentage = max(1, min(percentage, 100))
|
||||
|
||||
# Process parameters
|
||||
factor = percentage/100.0
|
||||
hsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
|
||||
|
||||
# Initialize the led data
|
||||
snakeLeds = max(1, int(hyperion.ledCount*factor))
|
||||
ledData = bytearray()
|
||||
|
||||
for i in range(hyperion.ledCount-snakeLeds):
|
||||
ledData += bytearray((0, 0, 0))
|
||||
color_hsv = colorsys.rgb_to_hsv(color[0]/255.0,color[1]/255.0,color[2]/255.0)
|
||||
backgroundColor_hsv = colorsys.rgb_to_hsv(backgroundColor[0]/255.0,backgroundColor[1]/255.0,backgroundColor[2]/255.0)
|
||||
|
||||
for i in range(1,snakeLeds+1):
|
||||
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]*(snakeLeds-i)/snakeLeds)
|
||||
for i in range(hyperion.ledCount-snakeLeds):
|
||||
ledData += bytearray((int(backgroundColor[0]), int(backgroundColor[1]), int(backgroundColor[2])))
|
||||
|
||||
def lerp(a, b, t):
|
||||
return (a[0]*(1-t)+b[0]*t, a[1]*(1-t)+b[1]*t, a[2]*(1-t)+b[2]*t)
|
||||
|
||||
for i in range(0, snakeLeds):
|
||||
hsv = lerp(color_hsv, backgroundColor_hsv, 1.0/(snakeLeds-1)*i)
|
||||
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2])
|
||||
ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)))
|
||||
|
||||
# Calculate the sleep time and rotation increment
|
||||
|
Reference in New Issue
Block a user