-
Notifications
You must be signed in to change notification settings - Fork 0
/
random-fade.py
executable file
·50 lines (45 loc) · 1.2 KB
/
random-fade.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import led,random,time
SLEEPTIME=0.08
FADESIZE=80
def interpolate_tuple( start, end, steps ):
start_red = start[0]
start_green = start[1]
start_blue = start[2]
target_red = end[0]
target_green = end[1]
target_blue = end[2]
diff_red = target_red - start_red
diff_green = target_green - start_green
diff_blue = target_blue - start_blue
buf = []
for i in range(0, steps +1):
r = start_red + (diff_red * i / steps)
g = start_green + (diff_green * i / steps)
b = start_blue + (diff_blue * i / steps)
buf.append([r,g,b])
return buf
def random_color():
unc=[random.randrange(0, 255),random.randrange(0, 255),random.randrange(0, 255)]
hc=0
cln=[]
for c in unc:
if c>30:
hc+=1
if hc>2:
cln=[unc[0],unc[1],random.randrange(0, 5)]
else:
cln=unc
random.shuffle(cln)
return cln
led=led.led()
col0=random_color()
while True:
col1=random_color()
colorlist=interpolate_tuple(col0,col1,FADESIZE)
for color in colorlist:
led.rgbw(color[0],color[1],color[2])
time.sleep(SLEEPTIME)
col0=col1
col1=random_color()