From 4784b4ec42d01b48ccf7ec6d1f741c5c9517c6de Mon Sep 17 00:00:00 2001 From: johan Date: Sat, 30 Nov 2013 17:42:57 +0100 Subject: [PATCH] Rainbow effects added Former-commit-id: deb3051bfb4209671680ccd1e5fb6fc07a69346c --- effects/rainbow-mood.py | 31 +++++++++++++++++++++++++++++++ effects/rainbow-swirl.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 effects/rainbow-mood.py create mode 100644 effects/rainbow-swirl.py diff --git a/effects/rainbow-mood.py b/effects/rainbow-mood.py new file mode 100644 index 00000000..bba368ab --- /dev/null +++ b/effects/rainbow-mood.py @@ -0,0 +1,31 @@ +import hyperion +import time +import colorsys + +# Get the rotation time +rotationTime = hyperion.args.get('rotation-time', 3.0) + +# Get the brightness +brightness = hyperion.args.get('brightness', 1.0) + +# Get the saturation +saturation = hyperion.args.get('saturation', 1.0) + +# Get the direction +reverse = hyperion.args.get('reverse', False) + +# Calculate the sleep time and hue increment +sleepTime = 0.1 +hueIncrement = sleepTime / rotationTime + +# Switch direction if needed +if reverse: + increment = -increment + +# Start the write data loop +hue = 0.0 +while not hyperion.abort(): + rgb = colorsys.hsv_to_rgb(hue, saturation, brightness) + hyperion.setColor(int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])) + hue = (hue + hueIncrement) % 1.0 + time.sleep(sleepTime) diff --git a/effects/rainbow-swirl.py b/effects/rainbow-swirl.py new file mode 100644 index 00000000..c55bf9d7 --- /dev/null +++ b/effects/rainbow-swirl.py @@ -0,0 +1,40 @@ +import hyperion +import time +import colorsys + +# Get the rotation time +rotationTime = hyperion.args.get('rotation-time', 3.0) + +# Get the brightness +brightness = hyperion.args.get('brightness', 1.0) + +# Get the saturation +saturation = hyperion.args.get('saturation', 1.0) + +# Get the direction +reverse = hyperion.args.get('reverse', False) + +# Initialize the led data +ledData = bytearray() +for i in range(hyperion.ledCount): + hue = float(i)/hyperion.ledCount + rgb = colorsys.hsv_to_rgb(hue, saturation, brightness) + ledData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2]))) + +# Calculate the sleep time and rotation increment +increment = 3 +sleepTime = rotationTime / hyperion.ledCount +while sleepTime < 0.05: + increment *= 2 + sleepTime *= 2 +increment %= hyperion.ledCount + +# Switch direction if needed +if reverse: + increment = -increment + +# Start the write data loop +while not hyperion.abort(): + hyperion.setColor(ledData) + ledData = ledData[-increment:] + ledData[:-increment] + time.sleep(sleepTime)