-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathunicorn-hd-shutdown.py
85 lines (72 loc) · 1.81 KB
/
unicorn-hd-shutdown.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# #!/usr/bin/env python
import colorsys
import math
import time
import signal
import sys
import unicornhat as unicorn
def Shutdown(Code, Frame):
unicorn.off()
sys.exit(0)
signal.signal(signal.SIGTERM, Shutdown)
unicorn.set_layout(unicorn.HAT)
unicorn.rotation(0)
unicorn.brightness(0.5)
width,height=unicorn.get_shape()
i = 0.0
offset = 30
try:
while True:
i = i + 0.3
for y in range(height):
for x in range(width):
r = 0#x * 32
g = 0#y * 32
xy = x + y / 4
r = (math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64.0 + 128.0
g = (math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64.0 + 128.0
b = (math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64.0 + 128.0
r = max(0, min(255, r + offset))
g = max(0, min(255, g + offset))
b = max(0, min(255, b + offset))
unicorn.set_pixel(x,y,int(r),int(g),int(b))
unicorn.show()
time.sleep(0.01)
except KeyboardInterrupt:
unicorn.off()
import colorsys
import math
import time
import signal
import sys
import unicornhat as unicorn
def Shutdown(Code, Frame):
unicorn.off()
sys.exit(0)
signal.signal(signal.SIGTERM, Shutdown)
unicorn.set_layout(unicorn.HAT)
unicorn.rotation(0)
unicorn.brightness(0.5)
width,height=unicorn.get_shape()
i = 0.0
offset = 30
try:
while True:
i = i + 0.3
for y in range(height):
for x in range(width):
r = 0#x * 32
g = 0#y * 32
xy = x + y / 4
r = (math.cos((x+i)/2.0) + math.cos((y+i)/2.0)) * 64.0 + 128.0
g = (math.sin((x+i)/1.5) + math.sin((y+i)/2.0)) * 64.0 + 128.0
b = (math.sin((x+i)/2.0) + math.cos((y+i)/1.5)) * 64.0 + 128.0
r = max(0, min(255, r + offset))
g = max(0, min(255, g + offset))
b = max(0, min(255, b + offset))
unicorn.set_pixel(x,y,int(r),int(g),int(b))
unicorn.show()
time.sleep(0.01)
except KeyboardInterrupt:
unicorn.off()