|
| 1 | +import hyperion |
| 2 | +import time |
| 3 | +import colorsys |
| 4 | + |
| 5 | +# Get the parameters |
| 6 | +rotationTime = float(hyperion.args.get('rotation-time', 10.0)) |
| 7 | +color = hyperion.args.get('color', (255,0,0)) |
| 8 | +percentage = int(hyperion.args.get('percentage', 10)) |
| 9 | + |
| 10 | +# Check parameters |
| 11 | +rotationTime = max(0.1, rotationTime) |
| 12 | +percentage = max(1, min(percentage, 100)) |
| 13 | + |
| 14 | +# Process parameters |
| 15 | +factor = percentage/100.0 |
| 16 | +hsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0) |
| 17 | + |
| 18 | +# Initialize the led data |
| 19 | +snakeLeds = max(1, int(hyperion.ledCount*factor)) |
| 20 | +ledData = bytearray() |
| 21 | + |
| 22 | +for i in range(hyperion.ledCount-snakeLeds): |
| 23 | + ledData += bytearray((0, 0, 0)) |
| 24 | + |
| 25 | +for i in range(1,snakeLeds+1): |
| 26 | + rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/i) |
| 27 | + ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) |
| 28 | + |
| 29 | +# Calculate the sleep time and rotation increment |
| 30 | +increment = 3 |
| 31 | +sleepTime = rotationTime / hyperion.ledCount |
| 32 | +while sleepTime < 0.05: |
| 33 | + increment *= 2 |
| 34 | + sleepTime *= 2 |
| 35 | +increment %= hyperion.ledCount |
| 36 | + |
| 37 | +# Start the write data loop |
| 38 | +while not hyperion.abort(): |
| 39 | + hyperion.setColor(ledData) |
| 40 | + ledData = ledData[increment:] + ledData[:increment] |
| 41 | + time.sleep(sleepTime) |
0 commit comments