|
| 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 | +# Initialize the led data |
| 15 | +factor = float(percentage)/100.0 |
| 16 | +snakeLeds = int(hyperion.ledCount*factor) |
| 17 | +ledData = bytearray() |
| 18 | + |
| 19 | +for i in range(hyperion.ledCount-snakeLeds): |
| 20 | + ledData += bytearray((0, 0, 0)) |
| 21 | + |
| 22 | +for i in range(1, snakeLeds+1): |
| 23 | + hsv = colorsys.rgb_to_hsv(float(color[0])/float(255), float(color[1])/float(255), float(color[2])/float(255)) |
| 24 | + rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/float(snakeLeds+1-i)) |
| 25 | + ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) |
| 26 | + |
| 27 | +# Calculate the sleep time and rotation increment |
| 28 | +increment = 3 |
| 29 | +sleepTime = rotationTime / hyperion.ledCount |
| 30 | +while sleepTime < 0.05: |
| 31 | + increment *= 2 |
| 32 | + sleepTime *= 2 |
| 33 | +increment %= hyperion.ledCount |
| 34 | + |
| 35 | +# Start the write data loop |
| 36 | +while not hyperion.abort(): |
| 37 | + hyperion.setColor(ledData) |
| 38 | + ledData = ledData[-increment:] + ledData[:-increment] |
| 39 | + time.sleep(sleepTime) |
0 commit comments