1 class BlankPattern extends SCPattern {
2 BlankPattern(GLucose glucose) {
6 public void run(double deltaMs) {
11 abstract class TestPattern extends SCPattern {
12 public TestPattern(GLucose glucose) {
18 class TestSpeakerMapping extends TestPattern {
19 TestSpeakerMapping(GLucose glucose) {
23 public void run(double deltaMs) {
25 for (Speaker speaker : model.speakers) {
26 for (Strip strip : speaker.strips) {
28 for (Point p : strip.points) {
29 colors[p.index] = lx.hsb(h % 360, 100, b);
39 class TestBassMapping extends TestPattern {
40 TestBassMapping(GLucose glucose) {
44 public void run(double deltaMs) {
45 int[] strips = { 2, 1, 0, 3, 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6 };
47 for (int si : strips) {
49 for (Point p : model.bassBox.strips.get(si).points) {
50 colors[p.index] = lx.hsb(h % 360, 100, b);
58 class TestFloorMapping extends TestPattern {
59 TestFloorMapping(GLucose glucose) {
63 public void run(double deltaMs) {
64 int[] strutIndices = {6, 5, 4, 3, 2, 1, 0, 7};
66 for (int si : strutIndices) {
68 for (Point p : model.bassBox.struts.get(si).points) {
69 colors[p.index] = lx.hsb(h % 360, 100, b);
74 int[] floorIndices = {0, 1, 2, 3};
76 for (int fi : floorIndices) {
78 for (Point p : model.boothFloor.strips.get(fi).points) {
79 colors[p.index] = lx.hsb(h, 100, b);
87 class TestPerformancePattern extends TestPattern {
89 final BasicParameter ops = new BasicParameter("OPS", 0);
90 final BasicParameter iter = new BasicParameter("ITER", 0);
92 TestPerformancePattern(GLucose glucose) {
98 public void run(double deltaMs) {
100 for (int j = 0; j < ops.getValuef() * 400000; ++j) {
104 if (iter.getValuef() < 0.25) {
105 for (Point p : model.points) {
106 colors[p.index] = lx.hsb(
107 (p.x*.1 + p.y*.1) % 360,
112 } else if (iter.getValuef() < 0.5) {
113 for (int i = 0; i < colors.length; ++i) {
115 (90 + model.px[i]*.1 + model.py[i]*.1) % 360,
120 } else if (iter.getValuef() < 0.75) {
121 for (int i = 0; i < colors.length; ++i) {
123 (180 + model.p[3*i]*.1 + model.p[3*i+1]*.1) % 360,
129 for (int i = 0; i < colors.length; ++i) {
131 (270 + model.x(i)*.1 + model.y(i)*.1) % 360,
140 class TestStripPattern extends TestPattern {
142 SinLFO d = new SinLFO(4, 40, 4000);
144 public TestStripPattern(GLucose glucose) {
146 addModulator(d).trigger();
149 public void run(double deltaMs) {
150 for (Strip s : model.strips) {
151 for (Point p : s.points) {
152 colors[p.index] = lx.hsb(
155 max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy))
163 * Simplest demonstration of using the rotating master hue.
164 * All pixels are full-on the same color.
166 class TestHuePattern extends TestPattern {
167 public TestHuePattern(GLucose glucose) {
171 public void run(double deltaMs) {
172 // Access the core master hue via this method call
173 float hv = lx.getBaseHuef();
174 for (int i = 0; i < colors.length; ++i) {
175 colors[i] = lx.hsb(hv, 100, 100);
181 * Test of a wave moving across the X axis.
183 class TestXPattern extends TestPattern {
184 private final SinLFO xPos = new SinLFO(0, model.xMax, 4000);
185 public TestXPattern(GLucose glucose) {
187 addModulator(xPos).trigger();
189 public void run(double deltaMs) {
190 float hv = lx.getBaseHuef();
191 for (Point p : model.points) {
192 // This is a common technique for modulating brightness.
193 // You can use abs() to determine the distance between two
194 // values. The further away this point is from an exact
195 // point, the more we decrease its brightness
196 float bv = max(0, 100 - abs(p.x - xPos.getValuef()));
197 colors[p.index] = lx.hsb(hv, 100, bv);
203 * Test of a wave on the Y axis.
205 class TestYPattern extends TestPattern {
206 private final SinLFO yPos = new SinLFO(0, model.yMax, 4000);
207 public TestYPattern(GLucose glucose) {
209 addModulator(yPos).trigger();
211 public void run(double deltaMs) {
212 float hv = lx.getBaseHuef();
213 for (Point p : model.points) {
214 float bv = max(0, 100 - abs(p.y - yPos.getValuef()));
215 colors[p.index] = lx.hsb(hv, 100, bv);
221 * Test of a wave on the Z axis.
223 class TestZPattern extends TestPattern {
224 private final SinLFO zPos = new SinLFO(0, model.zMax, 4000);
225 public TestZPattern(GLucose glucose) {
227 addModulator(zPos).trigger();
229 public void run(double deltaMs) {
230 float hv = lx.getBaseHuef();
231 for (Point p : model.points) {
232 float bv = max(0, 100 - abs(p.z - zPos.getValuef()));
233 colors[p.index] = lx.hsb(hv, 100, bv);
239 * This shows how to iterate over towers, enumerated in the model.
241 class TestTowerPattern extends TestPattern {
242 private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size());
244 public TestTowerPattern(GLucose glucose) {
246 addModulator(towerIndex).trigger();
249 public void run(double deltaMs) {
251 for (Tower t : model.towers) {
252 for (Point p : t.points) {
253 colors[p.index] = lx.hsb(
256 max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size()))
266 * This is a demonstration of how to use the projection library. A projection
267 * creates a mutation of the coordinates of all the points in the model, creating
268 * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
269 * art car. However, since in reality the car does not move, the result is that
270 * it appears that the object we are drawing on the car is actually moving.
272 * Keep in mind that what we are creating a projection of is the view coordinates.
273 * Depending on your intuition, some operations may feel backwards. For instance,
274 * if you translate the view to the right, it will make it seem that the object
275 * you are drawing has moved to the left. If you scale the view up 2x, objects
276 * drawn with the same absolute values will seem to be half the size.
278 * If this feels counterintuitive at first, don't worry. Just remember that you
279 * are moving the pixels, not the structure. We're dealing with a finite set
280 * of sparse, non-uniformly spaced pixels. Mutating the structure would move
281 * things to a space where there are no pixels in 99% of the cases.
283 class TestProjectionPattern extends TestPattern {
285 private final Projection projection;
286 private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
287 private final SinLFO yPos = new SinLFO(-20, 40, 5000);
289 public TestProjectionPattern(GLucose glucose) {
291 projection = new Projection(model);
292 addModulator(angle).trigger();
293 addModulator(yPos).trigger();
296 public void run(double deltaMs) {
297 // For the same reasons described above, it may logically feel to you that
298 // some of these operations are in reverse order. Again, just keep in mind that
299 // the car itself is what's moving, not the object
300 projection.reset(model)
302 // Translate so the center of the car is the origin, offset by yPos
303 .translateCenter(model, 0, yPos.getValuef(), 0)
305 // Rotate around the origin (now the center of the car) about an X-vector
306 .rotate(angle.getValuef(), 1, 0, 0)
308 // Scale up the Y axis (objects will look smaller in that access)
311 float hv = lx.getBaseHuef();
312 for (Coord c : projection) {
313 float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
314 // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
315 d = max(0, abs(c.y) - 10 + .1*abs(c.z) + .02*abs(c.x)); // plane / spear thing
316 colors[c.index] = lx.hsb(
317 (hv + .6*abs(c.x) + abs(c.z)) % 360,
319 constrain(140 - 40*d, 0, 100)
325 class TestCubePattern extends TestPattern {
327 private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60);
329 TestCubePattern(GLucose glucose) {
331 addModulator(index).start();
334 public void run(double deltaMs) {
335 for (Cube c : model.cubes) {
337 for (Point p : c.points) {
338 colors[p.index] = lx.hsb(
341 max(0, 100 - 80.*abs(i - index.getValuef()))
349 class MappingTool extends TestPattern {
351 private int cubeIndex = 0;
352 private int stripIndex = 0;
353 private int channelIndex = 0;
355 public final int MAPPING_MODE_ALL = 0;
356 public final int MAPPING_MODE_CHANNEL = 1;
357 public final int MAPPING_MODE_SINGLE_CUBE = 2;
358 public int mappingMode = MAPPING_MODE_ALL;
360 public final int CUBE_MODE_ALL = 0;
361 public final int CUBE_MODE_SINGLE_STRIP = 1;
362 public final int CUBE_MODE_STRIP_PATTERN = 2;
363 public int cubeMode = CUBE_MODE_ALL;
365 public boolean channelModeRed = true;
366 public boolean channelModeGreen = false;
367 public boolean channelModeBlue = false;
369 private final int numChannels;
371 private final PandaMapping[] pandaMappings;
372 private PandaMapping activePanda;
373 private ChannelMapping activeChannel;
375 MappingTool(GLucose glucose, PandaMapping[] pandaMappings) {
377 this.pandaMappings = pandaMappings;
378 numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
382 public int numChannels() {
386 private void setChannel() {
387 activePanda = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD];
388 activeChannel = activePanda.channelList[channelIndex % PandaMapping.CHANNELS_PER_BOARD];
391 private int indexOfCubeInChannel(Cube c) {
392 if (activeChannel.mode == ChannelMapping.MODE_CUBES) {
394 for (int index : activeChannel.objectIndices) {
395 if ((index >= 0) && (c == model.getCubeByRawIndex(index))) {
404 private void printInfo() {
405 println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
408 public void cube(int delta) {
409 int len = model.cubes.size();
410 cubeIndex = (len + cubeIndex + delta) % len;
414 public void strip(int delta) {
415 int len = Cube.STRIPS_PER_CUBE;
416 stripIndex = (len + stripIndex + delta) % len;
420 public void run(double deltaMs) {
426 if (channelModeRed) c |= r;
427 if (channelModeGreen) c |= g;
428 if (channelModeBlue) c |= b;
431 for (Cube cube : model.cubes) {
432 boolean cubeOn = false;
433 int indexOfCubeInChannel = indexOfCubeInChannel(cube);
434 switch (mappingMode) {
435 case MAPPING_MODE_ALL: cubeOn = true; break;
436 case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
437 case MAPPING_MODE_CHANNEL: cubeOn = (indexOfCubeInChannel > 0); break;
440 if (mappingMode == MAPPING_MODE_CHANNEL) {
442 switch (indexOfCubeInChannel) {
443 case 1: cc = r; break;
444 case 2: cc = r|g; break;
445 case 3: cc = g; break;
446 case 4: cc = b; break;
447 case 5: cc = r|b; break;
450 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
453 for (Strip strip : cube.strips) {
454 int faceI = si / Face.STRIPS_PER_FACE;
456 case 0: sc = r; break;
457 case 1: sc = g; break;
458 case 2: sc = b; break;
459 case 3: sc = r|g|b; break;
461 if (si % Face.STRIPS_PER_FACE == 2) {
467 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
469 setColor(cube.strips.get(stripIndex), c);
480 public void setCube(int index) {
481 cubeIndex = index % model.cubes.size();
484 public void incCube() {
485 cubeIndex = (cubeIndex + 1) % model.cubes.size();
488 public void decCube() {
491 cubeIndex += model.cubes.size();
495 public void setChannel(int index) {
496 channelIndex = index % numChannels;
500 public void incChannel() {
501 channelIndex = (channelIndex + 1) % numChannels;
505 public void decChannel() {
506 channelIndex = (channelIndex + numChannels - 1) % numChannels;
510 public void setStrip(int index) {
511 stripIndex = index % Cube.STRIPS_PER_CUBE;
514 public void incStrip() {
515 stripIndex = (stripIndex + 1) % Cube.STRIPS_PER_CUBE;
518 public void decStrip() {
519 stripIndex = (stripIndex + Cube.STRIPS_PER_CUBE - 1) % Cube.STRIPS_PER_CUBE;
522 public void keyPressed(UIMapping uiMapping) {
524 case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break;
525 case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break;
526 case LEFT: decStrip(); break;
527 case RIGHT: incStrip(); break;
530 case 'r': channelModeRed = !channelModeRed; break;
531 case 'g': channelModeGreen = !channelModeGreen; break;
532 case 'b': channelModeBlue = !channelModeBlue; break;
534 uiMapping.setChannelID(channelIndex+1);
535 uiMapping.setCubeID(cubeIndex+1);
536 uiMapping.setStripID(stripIndex+1);