-
Notifications
You must be signed in to change notification settings - Fork 0
/
effects.go
235 lines (214 loc) · 4.89 KB
/
effects.go
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package main
/*
func emergency(canvas *ledclient.Canvas) {
blue := colorful.LinearRgb(0, 0, 1.0).Clamped()
black := colorful.Hcl(0, 0, 0).Clamped()
_ = black
_, height := canvas.Size()
half := height / 2
offset := 0
for {
effect.Fill(canvas, black)
offset = (offset + half) % b.Max.Y
for blinks := 0; blinks < 2; blinks++ {
for x := b.Min.X; x < b.Max.X; x++ {
for y := offset; y < offset+half; y++ {
canvas.Set(x, y, blue)
}
}
time.Sleep(time.Millisecond * 20)
for x := b.Min.X; x < b.Max.X; x++ {
for y := offset; y < offset+half; y++ {
canvas.Set(x, y, black)
}
}
time.Sleep(time.Millisecond * 20)
for x := b.Min.X; x < b.Max.X; x++ {
for y := offset; y < offset+half; y++ {
canvas.Set(x, y, blue)
}
}
}
time.Sleep(time.Millisecond * 20)
}
}
func northernLights(canvas *ledclient.Canvas) {
width, height := canvas.Size()
old := make([]colorful.Color, b.Max.X*b.Max.Y)
for {
for angle := 0.0; angle < 360.0; angle++ {
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
i := (y * b.Max.X) + x
col := colorful.Hsl(angle+rand.Float64()*50.0, 1, rand.Float64()*0.1)
step := col.BlendHcl(old[i], 0.92).Clamped()
canvas.Set(x, y, step)
old[i] = step
}
}
time.Sleep(time.Millisecond * 50)
}
}
}
func northernLightsStable(canvas *ledclient.Canvas) {
angle := 80.0
angle = 180.0
def := colorful.Hcl(angle, 1.0, 0.05)
effect.Fill(canvas, def)
for {
effect.FillFunc(canvas, func(x, y int, c colorful.Color) colorful.Color {
if rand.Intn(100) != 0 {
return def.BlendRgb(c, 0.98)
}
a := 180.0 * (1.0 / float64(rand.Intn(500)+1))
return colorful.Hcl(angle+a, 1, rand.Float64()*0.1)
})
time.Sleep(time.Millisecond * 10)
}
}
func black(canvas *ledclient.Canvas) {
effect.Fill(canvas, colorful.Hsv(0, 0, 0))
}
func white(canvas *ledclient.Canvas) {
effect.Fill(canvas, colorful.Hsv(0, 0, 1.0))
}
func snake(canvas *ledclient.Canvas) {
col := colorful.Hcl(0, 1, 0.1)
black(canvas)
b := canvas.Bounds()
for {
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
canvas.Set(x, y, col)
time.Sleep(time.Millisecond * 40)
}
}
}
}
func blinkWhite(canvas *ledclient.Canvas) {
for {
effect.Fill(canvas, colorful.Hcl(0, 0, 1.0))
time.Sleep(time.Millisecond * 1000)
effect.Fill(canvas, colorful.Hcl(0, 0, 0))
time.Sleep(time.Millisecond * 1000)
}
}
func split(canvas *ledclient.Canvas) {
l := 0.15
left := colorful.Hcl(30.0, 1.0, l).Clamped()
right := colorful.Hcl(180.0, 1.0, l).Clamped()
b := canvas.Bounds()
half := b.Max.Y / 2
for {
for x := b.Min.X; x < b.Max.X; x++ {
for y := b.Min.Y; y < half; y++ {
canvas.Set(x, y, left)
}
for y := half; y < b.Max.Y; y++ {
canvas.Set(x, y, right)
}
}
time.Sleep(time.Millisecond * 1000)
}
}
func fullBlue(canvas *ledclient.Canvas) {
for {
col := colorful.Hcl(80, 1.0, 1.0)
effect.Fill(canvas, col)
time.Sleep(time.Microsecond * 1000)
}
}
func superGradients(canvas *ledclient.Canvas) {
for {
hue := rand.Float64() * 360.0
for deg := 0.0; deg <= 180.0; deg += 1 {
l := math.Sin(lib.Rad(deg))
col := colorful.Hsv(hue, 1.0, l*0.5).Clamped()
effect.Fill(canvas, col)
time.Sleep(time.Microsecond * 1500)
}
time.Sleep(time.Millisecond * 185)
}
}
// directionTest draws up a gradient on each strip.
func directionTest(canvas *ledclient.Canvas) {
c := 1.0
l := 0.05
src := colorful.Hcl(0.0, c, l)
dst := colorful.Hcl(160.0, c, l)
b := canvas.Bounds()
count := b.Max.X - b.Min.X
step := float64(1.0) / float64(count)
for {
for y := b.Min.Y; y < b.Max.Y; y++ {
n := 0.0
for x := b.Min.X; x < b.Max.X; x++ {
n += step
col := src.BlendHcl(dst, n).Clamped()
canvas.Set(x, y, col)
}
}
time.Sleep(time.Millisecond * 1000)
}
}
func gradients(canvas *ledclient.Canvas) {
var h, c, l float64
h = 0.0
c = 0.8
l = 0.5
_, _ = c, l
src := colorful.Hsv(h, 1, 1)
dst := colorful.Hsv(h, 1, 1)
for {
src = dst
h += 30
if h >= 360 {
h = 0
}
dst = colorful.Hsv(h, 1, 1)
fmt.Printf("hue=%.2f, blend %#v %#v\n", h, src, dst)
// interpolate between the two colors.
for n := 0.0; n < 1.0; n += 0.01 {
col := src.BlendHcl(dst, n).Clamped()
effect.Fill(canvas, col)
time.Sleep(time.Millisecond * 20)
}
}
}
func staccatoWheel(canvas *ledclient.Canvas) {
var h float64
for {
h += 31
if h > 360 {
h -= 360
}
col := colorful.Hsv(h, 1, 0.25).Clamped()
effect.Fill(canvas, col)
time.Sleep(time.Millisecond * 250)
}
}
func wheelHCL(canvas *ledclient.Canvas) {
var h float64
for {
h += 1
if h > 360 {
h = 0
}
col := colorful.Hcl(h, 0.2, 0).Clamped()
effect.Fill(canvas, col)
time.Sleep(time.Millisecond * 100)
}
}
func wheelHSV(canvas *ledclient.Canvas) {
var h float64
for {
h += 1
if h > 360 {
h = 0
}
col := colorful.Hsv(h, 1, 1)
effect.Fill(canvas, col)
time.Sleep(time.Millisecond * 50)
}
}
*/