-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainbow.py
executable file
·30 lines (26 loc) · 926 Bytes
/
rainbow.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
#!/usr/bin/env python
import math
import time
from datetime import datetime
import unicornhat as unicorn
def rainbow(stop_time):
width,height=unicorn.get_shape()
i = 0.0
offset = 30
while int(datetime.now().strftime("%H%M")) < stop_time:
i = i + 0.3
for y in range(height):
for x in range(width):
r = 0
g = 0
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)
if __name__ == "__main__":
rainbow(2359)