-
Notifications
You must be signed in to change notification settings - Fork 0
/
greenDrip.py
79 lines (65 loc) · 2.38 KB
/
greenDrip.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
import random
import math
import time
from client import lightStripClient as lights
from widgets import volume
volume.scale = 0.5
if __name__ == '__main__':
lights.initialize('/dev/ttyACM0')
print ("CLIENT CONNECTED")
palette = [(0, 50, 0),
(20,50,0),
(0,0,0),
(0,0,0),
(0,0,0),
(0,0,0),
(0,0,0),
(0,0,0),
(0,0,0),
(0,0,0),
(0,0,0),
(0,50,20)]
backdrop = [ (0, 0, 0), ] * 263
redHaze = [(0,0,0)]*50 + [(100,255,100)]*213
def randomInsert():
global backdrop
sliceIndex = random.randint(0,263)
backdrop = backdrop[:sliceIndex] + [random.choice(palette)] + backdrop[sliceIndex:]
backdrop = backdrop[-263:]
def smooth(backdrop):
newBackdrop = []
for i, pixel in enumerate(backdrop):
before = backdrop[i-1]
after = backdrop[(i+1)%263]
newBackdrop.append((
int((before[0] + pixel[0] + after[0])/3),
int((before[1] + pixel[1] + after[1])/3),
int((before[2] + pixel[2] + after[2])/3),
))
return newBackdrop
def pushInsert():
global backdrop
backdrop = backdrop[1:] + [random.choice(palette)]
def pixelAverage(pixel1, pixel2, amnt1=0.5, amnt2=0.5):
return (
pixel1[0]*amnt1 + pixel2[0]*amnt2,
pixel1[1]*amnt1 + pixel2[1]*amnt2,
pixel1[2]*amnt1 + pixel2[2]*amnt2,
)
while True:
randomInsert()
pushInsert()
backdropPostProcess = backdrop.copy()
for i, pixel in enumerate(backdrop):
backdropPostProcess[i] = pixelAverage(pixel, pixel, amnt1 = 1, amnt2 = 0.3)
backdropPostProcess[i] = pixelAverage(backdropPostProcess[i], redHaze[i], amnt1 = 0.95, amnt2 = 0.015)
backdropPostProcess = smooth(backdropPostProcess)
commandList = []
commandList += lights.pixelListToCommandList(backdropPostProcess, 0)
commandList += lights.pixelListToCommandList(volume.toPixels(), 0)
commandList.append(lights.render())
lights.compressCommandList(commandList)
print(commandList)
lights.send(commandList)
time.sleep(0.015)
#input("NEXT")