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

Former-commit-id: c13cb44cfe48314c087cf6b80257317a38f260ba
This commit is contained in:
tostadora 2014-02-05 09:14:42 +01:00
parent faee31c83f
commit e6ebd6696b
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) rotationTime = max(0.1, rotationTime)
percentage = max(1, min(percentage, 100)) 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 # Initialize the led data
factor = float(percentage)/100.0 snakeLeds = max(1, int(hyperion.ledCount*factor))
snakeLeds = int(hyperion.ledCount*factor) decrement = hsv[2]/snakeLeds
ledData = bytearray() ledData = bytearray()
for i in range(hyperion.ledCount-snakeLeds): for i in range(hyperion.ledCount-snakeLeds):
ledData += bytearray((0, 0, 0)) ledData += bytearray((0, 0, 0))
for i in range(1, snakeLeds+1): for i in range(snakeLeds):
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]-(i*decrement))
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]/float(snakeLeds+1-i))
ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)))
# Calculate the sleep time and rotation increment # Calculate the sleep time and rotation increment