hyperion.ng/effects/rainbow-mood.py
johan 9954cb3e0d Added parameter value checks to effects
Former-commit-id: daf5d46862d9deeb12df56d262c7a0026a191a25
2013-12-01 15:22:51 +01:00

31 lines
831 B
Python

import hyperion
import time
import colorsys
# Get the parameters
rotationTime = hyperion.args.get('rotation-time', 3.0)
brightness = hyperion.args.get('brightness', 1.0)
saturation = hyperion.args.get('saturation', 1.0)
reverse = 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))
# 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)