From e6ebd6696b843b788e0ed816c148c904dd298149 Mon Sep 17 00:00:00 2001 From: tostadora Date: Wed, 5 Feb 2014 09:14:42 +0100 Subject: [PATCH] clear code and change the decrement of value to make it even Former-commit-id: c13cb44cfe48314c087cf6b80257317a38f260ba --- effects/snake.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/effects/snake.py b/effects/snake.py index 0ee622a6..c400c775 100644 --- a/effects/snake.py +++ b/effects/snake.py @@ -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