mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Create police.py
Former-commit-id: 97f31beef808c6b4950d598affc5259bbc8edee4
This commit is contained in:
parent
da914e0135
commit
7d9de67449
46
effects/police.py
Normal file
46
effects/police.py
Normal file
@ -0,0 +1,46 @@
|
||||
import hyperion
|
||||
import time
|
||||
import colorsys
|
||||
|
||||
# Get the parameters
|
||||
rotationTime = float(hyperion.args.get('rotation-time', 2.0))
|
||||
colorOne = hyperion.args.get('color_one', (255,0,0))
|
||||
colorTwo = hyperion.args.get('color_two', (0,0,255))
|
||||
colorsCount = hyperion.args.get('colors_count', hyperion.ledCount/2)
|
||||
reverse = bool(hyperion.args.get('reverse', False))
|
||||
|
||||
# Check parameters
|
||||
rotationTime = max(0.1, rotationTime)
|
||||
colorsCount = min(hyperion.ledCount/2, colorsCount)
|
||||
|
||||
# Initialize the led data
|
||||
hsv1 = colorsys.rgb_to_hsv(colorOne[0]/255.0, colorOne[1]/255.0, colorOne[2]/255.0)
|
||||
hsv2 = colorsys.rgb_to_hsv(colorTwo[0]/255.0, colorTwo[1]/255.0, colorTwo[2]/255.0)
|
||||
colorBlack = (0,0,0)
|
||||
ledData = bytearray()
|
||||
for i in range(hyperion.ledCount):
|
||||
if i <= colorsCount:
|
||||
rgb = colorsys.hsv_to_rgb(hsv1[0], hsv1[1], hsv1[2])
|
||||
elif (i >= hyperion.ledCount/2-1) & (i < (hyperion.ledCount/2) + colorsCount):
|
||||
rgb = colorsys.hsv_to_rgb(hsv2[0], hsv2[1], hsv2[2])
|
||||
else:
|
||||
rgb = colorBlack
|
||||
ledData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
|
||||
|
||||
# Calculate the sleep time and rotation increment
|
||||
increment = 3
|
||||
sleepTime = rotationTime / hyperion.ledCount
|
||||
while sleepTime < 0.05:
|
||||
increment *= 2
|
||||
sleepTime *= 2
|
||||
increment %= hyperion.ledCount
|
||||
|
||||
# Switch direction if needed
|
||||
if reverse:
|
||||
increment = -increment
|
||||
|
||||
# Start the write data loop
|
||||
while not hyperion.abort():
|
||||
hyperion.setColor(ledData)
|
||||
ledData = ledData[-increment:] + ledData[:-increment]
|
||||
time.sleep(sleepTime)
|
Loading…
Reference in New Issue
Block a user