2016-12-24 09:34:14 +01:00
|
|
|
import hyperion
|
|
|
|
import time
|
|
|
|
import colorsys
|
|
|
|
import random
|
|
|
|
|
|
|
|
min_len = int(hyperion.args.get('min_len', 3))
|
|
|
|
max_len = int(hyperion.args.get('max_len', 3))
|
2017-05-07 17:25:58 +02:00
|
|
|
#iHeight = int(hyperion.args.get('iHeight', 8))
|
2016-12-24 09:34:14 +01:00
|
|
|
trails = int(hyperion.args.get('int', 8))
|
2017-04-09 22:28:32 +02:00
|
|
|
sleepTime = float(hyperion.args.get('speed', 1)) / 1000.0
|
2016-12-24 09:34:14 +01:00
|
|
|
color = list(hyperion.args.get('color', (255,255,255)))
|
|
|
|
randomise = bool(hyperion.args.get('random', False))
|
2017-05-07 17:25:58 +02:00
|
|
|
iWidth = hyperion.imageWidth()
|
|
|
|
iHeight = hyperion.imageHeight()
|
2016-12-24 09:34:14 +01:00
|
|
|
|
|
|
|
class trail:
|
2017-04-09 22:28:32 +02:00
|
|
|
def __init__(self):
|
|
|
|
return
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
def start(self, x, y, step, color, _len, _h):
|
|
|
|
self.pos = 0.0
|
|
|
|
self.step = step
|
|
|
|
self.h = _h
|
|
|
|
self.x = x
|
|
|
|
self.data = []
|
|
|
|
brigtness = color[2]
|
|
|
|
step_brigtness = color[2] / _len
|
|
|
|
for i in range(0, _len):
|
|
|
|
rgb = colorsys.hsv_to_rgb(color[0], color[1], brigtness)
|
|
|
|
self.data.insert(0, (int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
|
|
|
|
brigtness -= step_brigtness
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
self.data.extend([(0,0,0)]*(_h-y))
|
|
|
|
if len(self.data) < _h:
|
|
|
|
for i in range (_h-len(self.data)):
|
|
|
|
self.data.insert(0, (0,0,0))
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
def getdata(self):
|
|
|
|
self.pos += self.step
|
|
|
|
if self.pos > 1.0:
|
|
|
|
self.pos = 0.0
|
|
|
|
self.data.pop()
|
|
|
|
self.data.insert(0, (0,0,0))
|
|
|
|
return self.x, self.data[-self.h:], all(x == self.data[0] for x in self.data)
|
2016-12-24 09:34:14 +01:00
|
|
|
|
|
|
|
tr = []
|
|
|
|
|
|
|
|
for i in range(trails):
|
2017-04-09 22:28:32 +02:00
|
|
|
r = {'exec': trail()}
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
if randomise:
|
2017-05-07 17:25:58 +02:00
|
|
|
col = (random.uniform(0.0, 1.0),1,1)
|
2017-04-09 22:28:32 +02:00
|
|
|
else:
|
|
|
|
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
r['exec'].start(
|
2017-05-07 17:25:58 +02:00
|
|
|
random.randint(0, iWidth),
|
|
|
|
random.randint(0, iHeight),
|
2017-04-09 22:28:32 +02:00
|
|
|
random.uniform(0.2, 0.8),
|
|
|
|
col,
|
|
|
|
random.randint(min_len, max_len),
|
2017-05-07 17:25:58 +02:00
|
|
|
iHeight
|
2017-04-09 22:28:32 +02:00
|
|
|
)
|
|
|
|
tr.append(r)
|
2016-12-24 09:34:14 +01:00
|
|
|
|
|
|
|
# Start the write data loop
|
|
|
|
while not hyperion.abort():
|
2017-04-09 22:28:32 +02:00
|
|
|
ledData = bytearray()
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
for r in tr:
|
|
|
|
r['x'], r['data'], c = r['exec'].getdata()
|
|
|
|
if c:
|
|
|
|
if randomise:
|
2017-05-07 17:25:58 +02:00
|
|
|
col = (random.uniform(0.0, 1.0),1,1)
|
2017-04-09 22:28:32 +02:00
|
|
|
else:
|
|
|
|
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-04-09 22:28:32 +02:00
|
|
|
r['exec'].start(
|
2017-05-07 17:25:58 +02:00
|
|
|
random.randint(0, iWidth),
|
|
|
|
random.randint(0, iHeight),
|
2017-04-09 22:28:32 +02:00
|
|
|
random.uniform(0.2, 0.8),
|
|
|
|
col,
|
|
|
|
random.randint(min_len, max_len),
|
2017-05-07 17:25:58 +02:00
|
|
|
iHeight
|
2017-04-09 22:28:32 +02:00
|
|
|
)
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-05-07 17:25:58 +02:00
|
|
|
for y in range(0, iHeight):
|
|
|
|
for x in range(0, iWidth):
|
2017-04-09 22:28:32 +02:00
|
|
|
for r in tr:
|
|
|
|
if x == r['x']:
|
|
|
|
led = bytearray(r['data'][y])
|
|
|
|
break
|
|
|
|
led = bytearray((0,0,0))
|
|
|
|
ledData += led
|
2016-12-24 09:34:14 +01:00
|
|
|
|
2017-05-07 17:25:58 +02:00
|
|
|
hyperion.setImage(iWidth,iHeight,ledData)
|
2017-04-09 22:28:32 +02:00
|
|
|
time.sleep(sleepTime)
|
2016-12-24 09:34:14 +01:00
|
|
|
|