2016-12-03 21:11:52 +01:00
|
|
|
import hyperion, time, colorsys
|
2016-01-17 18:19:33 +01:00
|
|
|
|
|
|
|
# Get the parameters
|
|
|
|
rotationTime = float(hyperion.args.get('rotation-time', 2.0))
|
2016-12-03 21:11:52 +01:00
|
|
|
colorOne = hyperion.args.get('color_one', (255,0,0))
|
|
|
|
colorTwo = hyperion.args.get('color_two', (0,0,255))
|
|
|
|
colorsCount = hyperion.args.get('colors_count', hyperion.ledCount/2)
|
|
|
|
reverse = bool(hyperion.args.get('reverse', False))
|
2016-01-17 18:19:33 +01:00
|
|
|
|
|
|
|
# Check parameters
|
|
|
|
rotationTime = max(0.1, rotationTime)
|
2016-12-03 21:11:52 +01:00
|
|
|
colorsCoun t = min(hyperion.ledCount/2, colorsCount)
|
2016-01-17 18:19:33 +01:00
|
|
|
|
|
|
|
# Initialize the led data
|
2016-12-03 21:11:52 +01:00
|
|
|
hsv1 = colorsys.rgb_to_hsv(colorOne[0]/255.0, colorOne[1]/255.0, colorOne[2]/255.0)
|
|
|
|
hsv2 = colorsys.rgb_to_hsv(colorTwo[0]/255.0, colorTwo[1]/255.0, colorTwo[2]/255.0)
|
2016-01-17 18:19:33 +01:00
|
|
|
colorBlack = (0,0,0)
|
2016-12-03 21:11:52 +01:00
|
|
|
ledData = bytearray()
|
2016-01-17 18:19:33 +01:00
|
|
|
for i in range(hyperion.ledCount):
|
|
|
|
if i <= colorsCount:
|
|
|
|
rgb = colorsys.hsv_to_rgb(hsv1[0], hsv1[1], hsv1[2])
|
|
|
|
elif (i >= hyperion.ledCount/2-1) & (i < (hyperion.ledCount/2) + colorsCount):
|
|
|
|
rgb = colorsys.hsv_to_rgb(hsv2[0], hsv2[1], hsv2[2])
|
|
|
|
else:
|
|
|
|
rgb = colorBlack
|
|
|
|
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)
|