Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit c13cb44

Browse files
committed
clear code and change the decrement of value to make it even
1 parent e19975e commit c13cb44

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

effects/snake.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@
1111
rotationTime = max(0.1, rotationTime)
1212
percentage = max(1, min(percentage, 100))
1313

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+
1418
# Initialize the led data
15-
factor = float(percentage)/100.0
16-
snakeLeds = int(hyperion.ledCount*factor)
19+
snakeLeds = max(1, int(hyperion.ledCount*factor))
20+
decrement = hsv[2]/snakeLeds
1721
ledData = bytearray()
1822

1923
for i in range(hyperion.ledCount-snakeLeds):
2024
ledData += bytearray((0, 0, 0))
2125

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))
26+
for i in range(snakeLeds):
27+
rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2]-(i*decrement))
2528
ledData += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255)))
2629

2730
# Calculate the sleep time and rotation increment

0 commit comments

Comments
 (0)