From faee31c83f7b3054f8660f0de243aa83b00bd4df Mon Sep 17 00:00:00 2001 From: tostadora Date: Tue, 4 Feb 2014 23:51:11 +0100 Subject: [PATCH 1/3] new effect! Former-commit-id: e19975e298fd6b11e7012739ac37ee3047d2c184 --- effects/snake.json | 10 ++++++++++ effects/snake.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 effects/snake.json create mode 100644 effects/snake.py diff --git a/effects/snake.json b/effects/snake.json new file mode 100644 index 00000000..2c7ba395 --- /dev/null +++ b/effects/snake.json @@ -0,0 +1,10 @@ +{ + "name" : "Snake", + "script" : "snake.py", + "args" : + { + "rotation-time" : 10.0, + "color" : [255, 0, 0], + "percentage" : 25 + } +} diff --git a/effects/snake.py b/effects/snake.py new file mode 100644 index 00000000..0ee622a6 --- /dev/null +++ b/effects/snake.py @@ -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) From e6ebd6696b843b788e0ed816c148c904dd298149 Mon Sep 17 00:00:00 2001 From: tostadora Date: Wed, 5 Feb 2014 09:14:42 +0100 Subject: [PATCH 2/3] clear code and change the decrement of value to make it even Former-commit-id: c13cb44cfe48314c087cf6b80257317a38f260ba --- effects/snake.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/effects/snake.py b/effects/snake.py index 0ee622a6..c400c775 100644 --- a/effects/snake.py +++ b/effects/snake.py @@ -11,17 +11,20 @@ percentage = int(hyperion.args.get('percentage', 10)) rotationTime = max(0.1, rotationTime) 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 -factor = float(percentage)/100.0 -snakeLeds = int(hyperion.ledCount*factor) +snakeLeds = max(1, int(hyperion.ledCount*factor)) +decrement = hsv[2]/snakeLeds 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)) +for i in range(snakeLeds): + rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]-(i*decrement)) ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) # Calculate the sleep time and rotation increment From b781c4403a6b4d611b38116d169c8aa23369d1b0 Mon Sep 17 00:00:00 2001 From: tostadora Date: Wed, 5 Feb 2014 19:24:36 +0100 Subject: [PATCH 3/3] back to the old decrement. It had a better effect Former-commit-id: a00b1c8c84c7846f760e7c0cec7d08949bd6e6b7 --- effects/snake.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/effects/snake.py b/effects/snake.py index c400c775..2ae5cb37 100644 --- a/effects/snake.py +++ b/effects/snake.py @@ -17,14 +17,13 @@ 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)) -decrement = hsv[2]/snakeLeds ledData = bytearray() for i in range(hyperion.ledCount-snakeLeds): ledData += bytearray((0, 0, 0)) -for i in range(snakeLeds): - rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]-(i*decrement)) +for i in range(1,snakeLeds+1): + rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/i) ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) # Calculate the sleep time and rotation increment @@ -38,5 +37,5 @@ increment %= hyperion.ledCount # Start the write data loop while not hyperion.abort(): hyperion.setColor(ledData) - ledData = ledData[-increment:] + ledData[:-increment] + ledData = ledData[increment:] + ledData[:increment] time.sleep(sleepTime)