-
Notifications
You must be signed in to change notification settings - Fork 0
/
animations.pde
324 lines (307 loc) · 7.94 KB
/
animations.pde
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
int makeRGB(int r, int g, int b) {
return (r << 16) | (g << 8) | b;
}
int shade(int c, float shadeFactor) {
int r = (c >> 16) & 0xFF;
int g = (c >> 8) & 0xFF;
int b = c & 0xFF;
int rr = int(r * (1.0 - shadeFactor));
int gg = int(g * (1.0 - shadeFactor));
int bb = int(b * (1.0 - shadeFactor));
return makeRGB(rr, gg, bb);
}
class Animation {
String name;
int speedPct;
int logicalClock;
int lastFrameCount;
public Integer primaryColor;
public Integer secondaryColor;
VirtualPixel pixels[];
Animation() {
// each animation gets a deep copy of the KS pixel model
this.pixels = new VirtualPixel[ksVirtualPixels.length];
this.speedPct = 50;
for (int i = 0; i < ksVirtualPixels.length; i++) {
VirtualPixel src = ksVirtualPixels[i];
pixels[i] = new VirtualPixel(src.controllerId, src.stripId, src.pixelId,
src.coord.x, src.coord.y, src.coord.z);
}
}
void resetClock() {
logicalClock = 0;
lastFrameCount = frameCount;
}
void tick() {
int frameDelta = frameCount-lastFrameCount;
float framesPerTick = (float(globalFrameRate)/2.0) - (float(globalFrameRate) * (float(speedPct)/100.0));
if (frameDelta < framesPerTick) return;
lastFrameCount = frameCount;
logicalClock++;
}
}
class OffAnimation extends Animation {
OffAnimation() {
name = "off";
speedPct = 50;
}
}
// show the KS brand colors
class BrandAnimation extends Animation {
BrandAnimation() {
name = "brand";
primaryColor = 0x009900;
secondaryColor = 0x8B008B;
}
void tick() {
super.tick();
for (VirtualPixel vp : pixels) {
// make this a diagonal
if (vp.coord.x < divider(int(vp.coord.y))) {
vp.currentColor = primaryColor;
} else {
vp.currentColor = secondaryColor;
}
}
}
int divider(int y) {
return -y + 275;
}
}
class ThumperAnimation extends Animation {
final int thumperPurple = 0x660E6F;
ThumperAnimation() {
name = "thumper";
speedPct = 50;
}
void tick() {
super.tick();
// rain effect
int numBuckets = 100;
float yRange = maxY - minY;
int activeBucket = logicalClock % numBuckets;
float bucketHeight = yRange / float(numBuckets);
float yActiveStart = minY + (activeBucket*bucketHeight);
float yActiveEnd = yActiveStart + bucketHeight;
for (VirtualPixel vp : pixels) {
if (vp.coord.y >= yActiveStart && vp.coord.y < yActiveEnd) {
vp.currentColor = thumperPurple;
} else {
vp.currentColor = 0x000000;
}
}
}
}
class SolidAnimation extends Animation {
SolidAnimation() {
name = "solid";
primaryColor = 0x009900;
}
void tick() {
super.tick();
for (VirtualPixel vp : pixels) {
vp.currentColor = primaryColor;
}
}
}
class SolidGlowAnimation extends Animation {
SolidGlowAnimation() {
name = "solidglow";
primaryColor = 0x009900;
}
void tick() {
super.tick();
int phase = logicalClock % 200;
if (phase > 100) { phase = 100 - (phase-100); }
int c = shade(primaryColor, 1.0 - (float(phase) / 100.0));
for (VirtualPixel vp : pixels) {
vp.currentColor = c;
}
}
}
class SolidGlowRandAnimation extends Animation {
int glowColor = (int)random(0xFFFFFF);
SolidGlowRandAnimation() {
name = "solidglow-rnd";
}
void tick() {
super.tick();
int phase = logicalClock % 200;
if (phase == 0) { glowColor = (int)random(0xFFFFFF); }
if (phase > 100) { phase = 100 - (phase-100); }
int c = shade(glowColor, 1.0 - (float(phase) / 100.0));
for (VirtualPixel vp : pixels) {
vp.currentColor = c;
}
}
}
class ScanAnimation extends Animation {
ScanAnimation() {
name = "scan";
primaryColor = 0x009900;
secondaryColor = 0x000000;
}
void tick() {
super.tick();
int numBuckets = 100;
float xRange = maxX - minX;
int activeBucket = logicalClock % numBuckets;
float bucketHeight = xRange / float(numBuckets);
float xActiveStart = minX + (activeBucket*bucketHeight);
float xActiveEnd = xActiveStart + bucketHeight;
for (VirtualPixel vp : pixels) {
if (vp.coord.x >= xActiveStart && vp.coord.x < xActiveEnd) {
vp.currentColor = primaryColor;
} else {
vp.currentColor = secondaryColor;
}
}
}
}
class NoiseAnimation extends Animation {
NoiseAnimation() {
name = "noise";
primaryColor = 0x009900;
speedPct = 10;
}
void tick() {
super.tick();
for (VirtualPixel vp : pixels) {
if (random(100) < speedPct) {
vp.currentColor = primaryColor;
} else {
vp.currentColor = 0;
}
}
}
}
class RandomNoiseAnimation extends Animation {
RandomNoiseAnimation() {
name = "randomnoise";
primaryColor = null;
speedPct = 10;
}
void tick() {
super.tick();
for (VirtualPixel vp : pixels) {
if (random(100) < speedPct) {
vp.currentColor = makeRGB(int(random(255)), int(random(255)), int(random(255)));
} else {
vp.currentColor = 0;
}
}
}
}
float dist(VirtualPixel vp, float x, float y, float z) {
return sqrt(pow(x-vp.coord.x, 2) + pow(y-vp.coord.y, 2) + pow(z-vp.coord.z, 2));
}
class RadiateDJAnimation extends Animation {
RadiateDJAnimation() {
name = "radiate-dj";
primaryColor = 0x990000;
secondaryColor = 0x0;
speedPct=75;
}
int djX = 210;
int djY = 30;
int djZ = 30;
void tick() {
super.tick();
int i = logicalClock % 200;
for (VirtualPixel vp : pixels) {
float d = dist(vp, djX, djY, djZ);
if (d >= i && d < i+40) {
vp.currentColor = primaryColor;
} else if (d >= (i+40) && d < (i+80)) {
vp.currentColor = secondaryColor;
} else {
vp.currentColor = 0x0;
}
}
}
}
class RadiateRandAnimation extends Animation {
RadiateRandAnimation() {
name = "radiate-rnd";
primaryColor = 0x990000;
secondaryColor = 0x0;
speedPct = 75;
randomSpot();
}
int djX, djY, djZ;
void randomSpot() {
djX = (int)random(minX, maxX);
djY = (int)random(minY, maxY);
djZ = (int)random(-40, 40);
}
void tick() {
super.tick();
if (logicalClock % 180 == 0) {
randomSpot();
}
int i = logicalClock % 200;
for (VirtualPixel vp : pixels) {
float d = dist(vp, djX, djY, djZ);
if (d >= i && d < i+40) {
vp.currentColor = primaryColor;
} else if (d >= (i+40) && d < (i+80)) {
vp.currentColor = secondaryColor;
} else {
vp.currentColor = 0x0;
}
}
}
}
class RadiateSubwoofers extends Animation {
RadiateSubwoofers() {
name = "radiate-bass";
speedPct = 75;
// TODO: actually use the speed setting, right now it radiates very slowly
// (default speed is about ~60 pixels/second, the frame rate)
}
int subX = 210;
int subY = 110;
int subZ = 30;
void tick() {
super.tick();
for (VirtualPixel vp : pixels) {
int d = int(dist(vp, subX, subY, subZ));
int g = int(getSpectroAtDistance(d) * 1.5);
vp.currentColor = makeRGB(0,g,0);
}
}
}
String animations[] = {
"off",
"solid",
"solidglow",
"solidglow-rnd",
"brand",
"scan",
"noise",
"randomnoise",
"thumper",
"radiate-dj",
"radiate-rnd",
"radiate-bass",
};
Animation createAnimation(int i) {
switch (animations[i]) {
case "off" : return new OffAnimation();
case "solid" : return new SolidAnimation();
case "solidglow" : return new SolidGlowAnimation();
case "solidglow-rnd": return new SolidGlowRandAnimation();
case "brand" : return new BrandAnimation();
case "scan" : return new ScanAnimation();
case "noise" : return new NoiseAnimation();
case "randomnoise" : return new RandomNoiseAnimation();
case "thumper": return new ThumperAnimation();
case "radiate-dj": return new RadiateDJAnimation();
case "radiate-rnd":return new RadiateRandAnimation();
case "radiate-bass":return new RadiateSubwoofers();
default:
println("*** unknown animation: "+animations[i]);
exit();
return null;
}
}