-
Notifications
You must be signed in to change notification settings - Fork 9
/
TestPatterns.pde
393 lines (345 loc) · 11.1 KB
/
TestPatterns.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
abstract class TestPattern extends SCPattern {
public TestPattern(GLucose glucose) {
super(glucose);
setEligible(false);
}
}
class TestStripPattern extends TestPattern {
SinLFO d = new SinLFO(4, 40, 4000);
public TestStripPattern(GLucose glucose) {
super(glucose);
addModulator(d).trigger();
}
public void run(int deltaMs) {
for (Strip s : model.strips) {
for (Point p : s.points) {
colors[p.index] = color(
lx.getBaseHuef(),
100,
max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy))
);
}
}
}
}
/**
* Simplest demonstration of using the rotating master hue.
* All pixels are full-on the same color.
*/
class TestHuePattern extends TestPattern {
public TestHuePattern(GLucose glucose) {
super(glucose);
}
public void run(int deltaMs) {
// Access the core master hue via this method call
float hv = lx.getBaseHuef();
for (int i = 0; i < colors.length; ++i) {
colors[i] = color(hv, 100, 100);
}
}
}
/**
* Test of a wave moving across the X axis.
*/
class TestXPattern extends TestPattern {
private final SinLFO xPos = new SinLFO(0, model.xMax, 4000);
public TestXPattern(GLucose glucose) {
super(glucose);
addModulator(xPos).trigger();
}
public void run(int deltaMs) {
float hv = lx.getBaseHuef();
for (Point p : model.points) {
// This is a common technique for modulating brightness.
// You can use abs() to determine the distance between two
// values. The further away this point is from an exact
// point, the more we decrease its brightness
float bv = max(0, 100 - abs(p.fx - xPos.getValuef()));
colors[p.index] = color(hv, 100, bv);
}
}
}
/**
* Test of a wave on the Y axis.
*/
class TestYPattern extends TestPattern {
private final SinLFO yPos = new SinLFO(0, model.yMax, 4000);
public TestYPattern(GLucose glucose) {
super(glucose);
addModulator(yPos).trigger();
}
public void run(int deltaMs) {
float hv = lx.getBaseHuef();
for (Point p : model.points) {
float bv = max(0, 100 - abs(p.fy - yPos.getValuef()));
colors[p.index] = color(hv, 100, bv);
}
}
}
/**
* Test of a wave on the Z axis.
*/
class TestZPattern extends TestPattern {
private final SinLFO zPos = new SinLFO(0, model.zMax, 4000);
public TestZPattern(GLucose glucose) {
super(glucose);
addModulator(zPos).trigger();
}
public void run(int deltaMs) {
float hv = lx.getBaseHuef();
for (Point p : model.points) {
float bv = max(0, 100 - abs(p.fz - zPos.getValuef()));
colors[p.index] = color(hv, 100, bv);
}
}
}
/**
* This shows how to iterate over towers, enumerated in the model.
*/
class TestTowerPattern extends TestPattern {
private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size());
public TestTowerPattern(GLucose glucose) {
super(glucose);
addModulator(towerIndex).trigger();
}
public void run(int deltaMs) {
int ti = 0;
for (Tower t : model.towers) {
for (Point p : t.points) {
colors[p.index] = color(
lx.getBaseHuef(),
100,
max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size()))
);
}
++ti;
}
}
}
/**
* This is a demonstration of how to use the projection library. A projection
* creates a mutation of the coordinates of all the points in the model, creating
* virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
* art car. However, since in reality the car does not move, the result is that
* it appears that the object we are drawing on the car is actually moving.
*
* Keep in mind that what we are creating a projection of is the view coordinates.
* Depending on your intuition, some operations may feel backwards. For instance,
* if you translate the view to the right, it will make it seem that the object
* you are drawing has moved to the left. If you scale the view up 2x, objects
* drawn with the same absolute values will seem to be half the size.
*
* If this feels counterintuitive at first, don't worry. Just remember that you
* are moving the pixels, not the structure. We're dealing with a finite set
* of sparse, non-uniformly spaced pixels. Mutating the structure would move
* things to a space where there are no pixels in 99% of the cases.
*/
class TestProjectionPattern extends TestPattern {
private final Projection projection;
private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
private final SinLFO yPos = new SinLFO(-20, 40, 5000);
public TestProjectionPattern(GLucose glucose) {
super(glucose);
projection = new Projection(model);
addModulator(angle).trigger();
addModulator(yPos).trigger();
}
public void run(int deltaMs) {
// For the same reasons described above, it may logically feel to you that
// some of these operations are in reverse order. Again, just keep in mind that
// the car itself is what's moving, not the object
projection.reset(model)
// Translate so the center of the car is the origin, offset by yPos
.translateCenter(model, 0, yPos.getValuef(), 0)
// Rotate around the origin (now the center of the car) about an X-vector
.rotate(angle.getValuef(), 1, 0, 0)
// Scale up the Y axis (objects will look smaller in that access)
.scale(1, 1.5, 1);
float hv = lx.getBaseHuef();
for (Coord c : projection) {
float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
// d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
d = max(0, abs(c.y) - 10 + .1*abs(c.z) + .02*abs(c.x)); // plane / spear thing
colors[c.index] = color(
(hv + .6*abs(c.x) + abs(c.z)) % 360,
100,
constrain(140 - 40*d, 0, 100)
);
}
}
}
class TestCubePattern extends TestPattern {
private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60);
TestCubePattern(GLucose glucose) {
super(glucose);
addModulator(index).start();
}
public void run(int deltaMs) {
for (Cube c : model.cubes) {
int i = 0;
for (Point p : c.points) {
colors[p.index] = color(
lx.getBaseHuef(),
100,
max(0, 100 - 80.*abs(i - index.getValuef()))
);
++i;
}
}
}
}
class MappingTool extends TestPattern {
private int cubeIndex = 0;
private int stripIndex = 0;
private int channelIndex = 0;
public final int MAPPING_MODE_ALL = 0;
public final int MAPPING_MODE_CHANNEL = 1;
public final int MAPPING_MODE_SINGLE_CUBE = 2;
public int mappingMode = MAPPING_MODE_ALL;
public final int CUBE_MODE_ALL = 0;
public final int CUBE_MODE_SINGLE_STRIP = 1;
public final int CUBE_MODE_STRIP_PATTERN = 2;
public int cubeMode = CUBE_MODE_ALL;
public boolean channelModeRed = true;
public boolean channelModeGreen = false;
public boolean channelModeBlue = false;
private final int numChannels;
private final PandaMapping[] pandaMappings;
private PandaMapping activePanda;
private ChannelMapping activeChannel;
MappingTool(GLucose glucose, PandaMapping[] pandaMappings) {
super(glucose);
this.pandaMappings = pandaMappings;
numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
setChannel();
}
private void setChannel() {
activePanda = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD];
activeChannel = activePanda.channelList[channelIndex % PandaMapping.CHANNELS_PER_BOARD];
}
private int indexOfCubeInChannel(Cube c) {
if (activeChannel.mode == ChannelMapping.MODE_CUBES) {
int i = 1;
for (int index : activeChannel.objectIndices) {
if (c == model.getCubeByRawIndex(index)) {
return i;
}
++i;
}
}
return 0;
}
private void printInfo() {
println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
}
public void cube(int delta) {
int len = model.cubes.size();
cubeIndex = (len + cubeIndex + delta) % len;
printInfo();
}
public void strip(int delta) {
int len = Cube.STRIPS_PER_CUBE;
stripIndex = (len + stripIndex + delta) % len;
printInfo();
}
public void run(int deltaMs) {
color off = color(0, 0, 0);
color c = off;
color r = #FF0000;
color g = #00FF00;
color b = #0000FF;
if (channelModeRed) c |= r;
if (channelModeGreen) c |= g;
if (channelModeBlue) c |= b;
int ci = 0;
for (Cube cube : model.cubes) {
boolean cubeOn = false;
int indexOfCubeInChannel = indexOfCubeInChannel(cube);
switch (mappingMode) {
case MAPPING_MODE_ALL: cubeOn = true; break;
case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
case MAPPING_MODE_CHANNEL: cubeOn = (channelIndex > 0); break;
}
if (cubeOn) {
if (mappingMode == MAPPING_MODE_CHANNEL) {
color cc = off;
switch (indexOfCubeInChannel) {
case 1: cc = r; break;
case 2: cc = r|g; break;
case 3: cc = g; break;
case 4: cc = b; break;
case 5: cc = r|b; break;
}
setColor(cube, cc);
} else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
int si = 0;
color sc = off;
for (Strip strip : cube.strips) {
int faceI = si / Face.STRIPS_PER_FACE;
switch (faceI) {
case 0: sc = r; break;
case 1: sc = g; break;
case 2: sc = b; break;
case 3: sc = r|g|b; break;
}
if (si % Face.STRIPS_PER_FACE == 2) {
sc = r|g;
}
setColor(strip, sc);
++si;
}
} else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
setColor(cube, off);
setColor(cube.strips.get(stripIndex), c);
} else {
setColor(cube, c);
}
} else {
setColor(cube, off);
}
++ci;
}
}
public void incCube() {
cubeIndex = (cubeIndex + 1) % model.cubes.size();
}
public void decCube() {
--cubeIndex;
if (cubeIndex < 0) {
cubeIndex += model.cubes.size();
}
}
public void incChannel() {
channelIndex = (channelIndex + 1) % numChannels;
setChannel();
}
public void decChannel() {
--channelIndex;
if (channelIndex < 0) {
channelIndex += numChannels;
}
setChannel();
}
public void incStrip() {
stripIndex = (stripIndex + 1) % Cube.STRIPS_PER_CUBE;
}
public void decStrip() {
--stripIndex;
if (stripIndex < 0) {
stripIndex += Cube.STRIPS_PER_CUBE;
}
}
public void keyPressed() {
switch (keyCode) {
case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break;
case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break;
case LEFT: decStrip(); break;
case RIGHT: incStrip(); break;
}
switch (key) {
case 'r': channelModeRed = !channelModeRed; break;
case 'g': channelModeGreen = !channelModeGreen; break;
case 'b': channelModeBlue = !channelModeBlue; break;
}
}
}