forked from penfold42/hyperion-effects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstripes.py
71 lines (57 loc) · 1.65 KB
/
stripes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import hyperion, time, colorsys, random
# Get the parameters
sleepTime = float(hyperion.args.get('AsleepTime', 0.01))
color = hyperion.args.get('color', (255,0,0))
text = hyperion.args.get('text', "Hello World")
# Check parameters
# Initialize the led data
width = 150
height = 5
imageData = bytearray(height * width * (0,0,0))
def ascii_to_offset(char):
chr = ord(char)
# symbnols, numbers, capital letters
if (chr>=0x20) and (chr<0x5b):
return chr-0x20;
# lower case letters
elif (chr>=0x61) and (chr<=0x7a):
return chr-0x40;
else:
return 0xff;
def setPixel(x,y,rgb):
global imageData, width
offset = y*width*3 + x*3
if offset+2 < len(imageData):
imageData[offset] = rgb[0]
imageData[offset+1] = rgb[1]
imageData[offset+2] = rgb[2]
def randomColor():
# color = colorsys.hsv_to_rgb(random.random() ,1, 1)
hue = sat = val = 1.0
hue = random.uniform(0, 0.999999)
# sat = random.random()
val = random.uniform(0.5, 0.9999)
color = colorsys.hsv_to_rgb(hue, sat, val)
color = ( int(color[0]*255), int(color[1]*255), int(color[2]*255) )
return color;
def stripe_lr(y):
global height, width, imageData
color = randomColor()
for x in range(0,width):
setPixel(x,y,color)
hyperion.setImage(width, height, imageData)
time.sleep(sleepTime)
def stripe_rl(y):
global height, width, imageData
color = randomColor()
for x in range(width-1, -1, -1):
setPixel(x,y,color)
hyperion.setImage(width, height, imageData)
time.sleep(sleepTime)
while not hyperion.abort():
# for y in range(0,height):
y = random.randrange(0,height)
if random.random() > 0.5:
stripe_lr(y)
else:
stripe_rl(y)