2017-03-30 06:20:20 +02:00
|
|
|
import hyperion, time, colorsys
|
2017-02-08 14:31:14 +01:00
|
|
|
from random import randint
|
|
|
|
|
2017-02-08 14:35:24 +01:00
|
|
|
#get args
|
2017-03-30 06:20:20 +02:00
|
|
|
rotationTime = float(hyperion.args.get('rotationTime', 4))
|
|
|
|
marginPos = float(hyperion.args.get('margin-pos', 2))
|
2017-02-08 14:35:24 +01:00
|
|
|
|
2017-02-08 14:31:14 +01:00
|
|
|
# define pacman
|
2017-02-15 15:53:35 +01:00
|
|
|
pacman = bytearray((255, 255, 0))
|
2017-02-08 14:31:14 +01:00
|
|
|
|
|
|
|
# define ghosts
|
2017-03-30 06:20:20 +02:00
|
|
|
redGuy = bytearray((255, 0, 0))
|
2017-02-08 14:31:14 +01:00
|
|
|
pinkGuy = bytearray((255, 184, 255))
|
|
|
|
blueGuy = bytearray((0, 255, 255))
|
|
|
|
slowGuy = bytearray((255, 184, 81))
|
|
|
|
|
|
|
|
light = bytearray((255, 184, 174))
|
|
|
|
background = bytearray((0, 0, 0))
|
|
|
|
|
2017-02-15 15:53:35 +01:00
|
|
|
#helper
|
2017-03-30 06:20:20 +02:00
|
|
|
posPac = 1
|
|
|
|
diffPac = 6*marginPos
|
|
|
|
diffGuys = 3*marginPos
|
|
|
|
sleepTime = max(0.02,rotationTime/hyperion.ledCount)
|
2017-02-15 15:53:35 +01:00
|
|
|
|
|
|
|
posPinkGuy = posPac + diffPac
|
|
|
|
posBlueGuy = posPinkGuy + diffGuys
|
|
|
|
posSlowGuy = posBlueGuy + diffGuys
|
|
|
|
posRedGuy = posSlowGuy + diffGuys
|
|
|
|
|
2017-02-08 14:31:14 +01:00
|
|
|
# initialize the led data
|
|
|
|
ledDataEscape = bytearray()
|
|
|
|
for i in range(hyperion.ledCount):
|
|
|
|
if i == 1:
|
|
|
|
ledDataEscape += pacman
|
2017-02-15 15:53:35 +01:00
|
|
|
elif i == posPinkGuy:
|
2017-02-08 14:31:14 +01:00
|
|
|
ledDataEscape += pinkGuy
|
2017-02-15 15:53:35 +01:00
|
|
|
elif i == posBlueGuy:
|
2017-02-08 14:31:14 +01:00
|
|
|
ledDataEscape += blueGuy
|
2017-02-15 15:53:35 +01:00
|
|
|
elif i == posSlowGuy:
|
2017-02-08 14:31:14 +01:00
|
|
|
ledDataEscape += slowGuy
|
2017-02-15 15:53:35 +01:00
|
|
|
elif i == posRedGuy:
|
2017-02-08 14:31:14 +01:00
|
|
|
ledDataEscape += redGuy
|
|
|
|
else:
|
|
|
|
ledDataEscape += background
|
|
|
|
|
|
|
|
ledDataChase = bytearray()
|
|
|
|
for i in range(hyperion.ledCount):
|
|
|
|
if i == 1:
|
|
|
|
ledDataChase += pacman
|
2017-02-15 15:53:35 +01:00
|
|
|
elif i in [posPinkGuy, posBlueGuy, posSlowGuy, posRedGuy]:
|
2017-02-08 14:31:14 +01:00
|
|
|
ledDataChase += bytearray((33, 33, 255))
|
|
|
|
else:
|
|
|
|
ledDataChase += background
|
|
|
|
|
|
|
|
# increment = 3, because LED-Color is defined by 3 Bytes
|
|
|
|
increment = 3
|
|
|
|
|
|
|
|
def shiftLED(ledData, increment, limit, lightPos=None):
|
|
|
|
state = 0
|
|
|
|
while state < limit and not hyperion.abort():
|
|
|
|
ledData = ledData[increment:] + ledData[:increment]
|
|
|
|
|
|
|
|
if (lightPos):
|
|
|
|
tmp = ledData[lightPos]
|
|
|
|
ledData[lightPos] = light
|
|
|
|
|
|
|
|
hyperion.setColor(ledData)
|
|
|
|
|
|
|
|
if (lightPos):
|
|
|
|
ledData[lightPos] = tmp
|
|
|
|
|
|
|
|
time.sleep(sleepTime)
|
|
|
|
state += 1
|
|
|
|
|
|
|
|
# start the write data loop
|
|
|
|
while not hyperion.abort():
|
|
|
|
|
|
|
|
# escape mode
|
|
|
|
ledData = ledDataEscape
|
|
|
|
shiftLED(ledData, increment, hyperion.ledCount)
|
|
|
|
|
|
|
|
random = randint(10,hyperion.ledCount)
|
|
|
|
|
|
|
|
# escape mode + power pellet
|
|
|
|
s = slice(3*random, 3*random+3)
|
|
|
|
shiftLED(ledData, increment, hyperion.ledCount - random, s)
|
|
|
|
|
|
|
|
# chase mode
|
2017-03-30 06:20:20 +02:00
|
|
|
shift = 3*(hyperion.ledCount - random)
|
|
|
|
ledData = ledDataChase[shift:]+ledDataChase[:shift]
|
2017-02-08 14:31:14 +01:00
|
|
|
shiftLED(ledData, -increment, 2*hyperion.ledCount-random)
|
2017-03-30 06:20:20 +02:00
|
|
|
time.sleep(sleepTime)
|
2017-02-08 14:31:14 +01:00
|
|
|
|