clear code and change the decrement of value to make it even

This commit is contained in:
tostadora 2014-02-05 09:14:42 +01:00
parent e19975e298
commit c13cb44cfe
1 changed files with 8 additions and 5 deletions

View File

@ -11,17 +11,20 @@ percentage = int(hyperion.args.get('percentage', 10))
rotationTime = max(0.1, rotationTime)
percentage = max(1, min(percentage, 100))
# Process parameters
factor = percentage/100.0
hsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
# Initialize the led data
factor = float(percentage)/100.0
snakeLeds = int(hyperion.ledCount*factor)
snakeLeds = max(1, int(hyperion.ledCount*factor))
decrement = hsv[2]/snakeLeds
ledData = bytearray()
for i in range(hyperion.ledCount-snakeLeds):
ledData += bytearray((0, 0, 0))
for i in range(1, snakeLeds+1):
hsv = colorsys.rgb_to_hsv(float(color[0])/float(255), float(color[1])/float(255), float(color[2])/float(255))
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/float(snakeLeds+1-i))
for i in range(snakeLeds):
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]-(i*decrement))
ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)))
# Calculate the sleep time and rotation increment