From c47ae445dc62d5e5de2719b68853e28ce006ab3b Mon Sep 17 00:00:00 2001 From: johan Date: Sun, 8 Dec 2013 12:46:14 +0100 Subject: [PATCH] Mood blobs effect added Former-commit-id: 4bae584f7fa0c688573ad6051458f99954ded686 --- effects/mood-blobs.py | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 effects/mood-blobs.py diff --git a/effects/mood-blobs.py b/effects/mood-blobs.py new file mode 100644 index 00000000..c9da30fe --- /dev/null +++ b/effects/mood-blobs.py @@ -0,0 +1,63 @@ +import hyperion +import time +import colorsys +import math + +# Get the parameters +rotationTime = hyperion.args.get('rotationTime', 20.0) +color = hyperion.args.get('color', (0,0,255)) +hueChange = hyperion.args.get('hueChange', 60.0) / 360.0 +blobs = hyperion.args.get('blobs', 5) +reverse = hyperion.args.get('reverse', False) +print color +print hyperion.args + +# Check parameters +rotationTime = max(0.1, rotationTime) +hueChange = max(0.0, min(abs(hueChange), .5)) +blobs = max(1, blobs) + +# Calculate the color data +baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0) +colorData = bytearray() +for i in range(hyperion.ledCount): + hue = (baseHsv[0] + hueChange * math.sin(2*math.pi * i / hyperion.ledCount)) % 1.0 + rgb = colorsys.hsv_to_rgb(hue, baseHsv[1], baseHsv[2]) + colorData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2]))) + +# Calculate the increments +sleepTime = 0.1 +amplitudePhaseIncrement = blobs * math.pi * sleepTime / rotationTime +colorDataIncrement = 3 + +# Switch direction if needed +if reverse: + amplitudePhaseIncrement = -amplitudePhaseIncrement + colorDataIncrement = -colorDataIncrement + +# create a Array for the colors +colors = bytearray(hyperion.ledCount * (0,0,0)) + +# Start the write data loop +amplitudePhase = 0.0 +rotateColors = False +while not hyperion.abort(): + # Calculate new colors + for i in range(hyperion.ledCount): + amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount)) + colors[3*i+0] = int(colorData[3*i+0] * amplitude) + colors[3*i+1] = int(colorData[3*i+1] * amplitude) + colors[3*i+2] = int(colorData[3*i+2] * amplitude) + + # set colors + hyperion.setColor(colors) + + # increment the phase + amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi) + + if rotateColors: + colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement] + rotateColors = not rotateColors + + # sleep for a while + time.sleep(sleepTime)