From de5b2849751537a334ab684d3d22591cc9ed8fd9 Mon Sep 17 00:00:00 2001 From: redpanther Date: Wed, 20 Jan 2016 22:36:21 +0100 Subject: [PATCH] modify effects - snake has a nice tail - random is not so fast anymore - merge sparks and sparks-color - make more params available in json files Former-commit-id: fc2a4f6f6ce2b44a35a75a9c0dbe36504b790be9 --- effects/random.json | 6 ++++-- effects/random.py | 18 +++++++----------- effects/snake.json | 8 ++++---- effects/snake.py | 2 +- effects/sparks-color.json | 11 +++++++++-- effects/sparks-color.py | 35 ----------------------------------- effects/sparks.json | 7 +++++++ effects/sparks.py | 32 ++++++++++++++++++-------------- 8 files changed, 50 insertions(+), 69 deletions(-) delete mode 100644 effects/sparks-color.py diff --git a/effects/random.json b/effects/random.json index 3dbc26d..4a85b13 100644 --- a/effects/random.json +++ b/effects/random.json @@ -1,7 +1,9 @@ { - "name" : "Random", + "name" : "Random", "script" : "random.py", - "args" : + "args" : { + "speed" : 1.0, + "saturation" : 1.0 } } diff --git a/effects/random.py b/effects/random.py index 0f5406b..63b56dc 100644 --- a/effects/random.py +++ b/effects/random.py @@ -1,24 +1,20 @@ -import hyperion -import time -import colorsys -import random +import hyperion, time, colorsys, random + +# get args +sleepTime = float(hyperion.args.get('speed', 1.0)) +saturation = float(hyperion.args.get('saturation', 1.0)) +ledData = bytearray() # Initialize the led data -ledData = bytearray() for i in range(hyperion.ledCount): ledData += bytearray((0,0,0)) -sleepTime = 0.001 - # Start the write data loop while not hyperion.abort(): hyperion.setColor(ledData) for i in range(hyperion.ledCount): if random.randrange(10) == 1: - hue = random.random() - sat = 1.0 - val = random.random() - rgb = colorsys.hsv_to_rgb(hue, sat, val) + rgb = colorsys.hsv_to_rgb(random.random(), saturation, random.random()) ledData[i*3 ] = int(255*rgb[0]) ledData[i*3+1] = int(255*rgb[1]) ledData[i*3+2] = int(255*rgb[2]) diff --git a/effects/snake.json b/effects/snake.json index eb914c8..d5a7674 100644 --- a/effects/snake.json +++ b/effects/snake.json @@ -1,10 +1,10 @@ { - "name" : "Snake", + "name" : "Snake", "script" : "snake.py", "args" : { - "rotation-time" : 10.0, - "color" : [255, 0, 0], - "percentage" : 25 + "rotation-time" : 12.0, + "color" : [255, 0, 0], + "percentage" : 10 } } diff --git a/effects/snake.py b/effects/snake.py index 2ae5cb3..d8d1656 100644 --- a/effects/snake.py +++ b/effects/snake.py @@ -23,7 +23,7 @@ for i in range(hyperion.ledCount-snakeLeds): ledData += bytearray((0, 0, 0)) for i in range(1,snakeLeds+1): - rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/i) + rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]*(snakeLeds-i)/snakeLeds) ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) # Calculate the sleep time and rotation increment diff --git a/effects/sparks-color.json b/effects/sparks-color.json index 641b7d8..e4d3649 100644 --- a/effects/sparks-color.json +++ b/effects/sparks-color.json @@ -1,7 +1,14 @@ { - "name" : "Sparks color", - "script" : "sparks-color.py", + "name" : "Sparks Color", + "script" : "sparks.py", "args" : { + "rotation-time" : 3.0, + "sleep-time" : 0.05, + "brightness" : 1.0, + "saturation" : 1.0, + "reverse" : false, + "color" : [255,255,255], + "random-color" : true } } diff --git a/effects/sparks-color.py b/effects/sparks-color.py deleted file mode 100644 index 34b5acf..0000000 --- a/effects/sparks-color.py +++ /dev/null @@ -1,35 +0,0 @@ -import hyperion -import time -import colorsys -import random - -# Get the parameters -rotationTime = float(hyperion.args.get('rotation-time', 3.0)) -brightness = float(hyperion.args.get('brightness', 1.0)) -saturation = float(hyperion.args.get('saturation', 1.0)) -reverse = bool(hyperion.args.get('reverse', False)) - -# Check parameters -rotationTime = max(0.1, rotationTime) -brightness = max(0.0, min(brightness, 1.0)) -saturation = max(0.0, min(saturation, 1.0)) - -# Initialize the led data -ledData = bytearray() - -sleepTime = 0.05 - -# Start the write data loop -while not hyperion.abort(): - ledData[:] = bytearray(3*hyperion.ledCount) - for i in range(hyperion.ledCount): - if random.random() < 0.005: - hue = random.random() - sat = 1 - val = 1 - rgb = colorsys.hsv_to_rgb(hue, sat, val) - ledData[i*3] = int(255*rgb[0]) - ledData[i*3+1] = int(255*rgb[1]) - ledData[i*3+2] = int(255*rgb[2]) - hyperion.setColor(ledData) - time.sleep(sleepTime) diff --git a/effects/sparks.json b/effects/sparks.json index f00c01a..0860987 100644 --- a/effects/sparks.json +++ b/effects/sparks.json @@ -3,5 +3,12 @@ "script" : "sparks.py", "args" : { + "rotation-time" : 3.0, + "sleep-time" : 0.05, + "brightness" : 1.0, + "saturation" : 1.0, + "reverse" : false, + "color" : [255,255,255], + "random-color" : false } } diff --git a/effects/sparks.py b/effects/sparks.py index 821719e..f215ba9 100644 --- a/effects/sparks.py +++ b/effects/sparks.py @@ -1,33 +1,37 @@ -import hyperion -import time -import colorsys -import random +import hyperion, time, colorsys, random # Get the parameters rotationTime = float(hyperion.args.get('rotation-time', 3.0)) -brightness = float(hyperion.args.get('brightness', 1.0)) -saturation = float(hyperion.args.get('saturation', 1.0)) -reverse = bool(hyperion.args.get('reverse', False)) +sleepTime = float(hyperion.args.get('sleep-time', 0.05)) +brightness = float(hyperion.args.get('brightness', 1.0)) +saturation = float(hyperion.args.get('saturation', 1.0)) +reverse = bool(hyperion.args.get('reverse', False)) +color = list(hyperion.args.get('color', (255,255,255))) +randomColor = bool(hyperion.args.get('random-color', False)) # Check parameters rotationTime = max(0.1, rotationTime) -brightness = max(0.0, min(brightness, 1.0)) -saturation = max(0.0, min(saturation, 1.0)) +brightness = max(0.0, min(brightness, 1.0)) +saturation = max(0.0, min(saturation, 1.0)) # Initialize the led data ledData = bytearray() for i in range(hyperion.ledCount): ledData += bytearray((0, 0, 0)) -sleepTime = 0.05 - # Start the write data loop while not hyperion.abort(): ledData[:] = bytearray(3*hyperion.ledCount) for i in range(hyperion.ledCount): if random.random() < 0.005: - ledData[i*3] = 255 - ledData[i*3+1] = 255 - ledData[i*3+2] = 255 + + if randomColor: + rgb = colorsys.hsv_to_rgb(random.random(), 1, 1) + for n in range(3): + color[n] = int(rgb[n]*255) + + for n in range(3): + ledData[i*3+n] = color[n] + hyperion.setColor(ledData) time.sleep(sleepTime)