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) {
99 if (iter.getValuef() > 0.5) {
100 for (int i = 0; i < colors.length; ++i) {
102 for (int j = 0; j < ops.getValuef() * 30; ++j) {
106 (lx.getBaseHuef() + model.px[i]*.2 + model.py[i]*.4) % 360,
112 for (Point p : model.points) {
114 for (int j = 0; j < ops.getValuef() * 30; ++j) {
117 colors[p.index] = lx.hsb(
118 (lx.getBaseHuef() + p.x*.2 + p.y*.4) % 360,
127 class TestStripPattern extends TestPattern {
129 SinLFO d = new SinLFO(4, 40, 4000);
131 public TestStripPattern(GLucose glucose) {
133 addModulator(d).trigger();
136 public void run(double deltaMs) {
137 for (Strip s : model.strips) {
138 for (Point p : s.points) {
139 colors[p.index] = lx.hsb(
142 max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy))
150 * Simplest demonstration of using the rotating master hue.
151 * All pixels are full-on the same color.
153 class TestHuePattern extends TestPattern {
154 public TestHuePattern(GLucose glucose) {
158 public void run(double deltaMs) {
159 // Access the core master hue via this method call
160 float hv = lx.getBaseHuef();
161 for (int i = 0; i < colors.length; ++i) {
162 colors[i] = lx.hsb(hv, 100, 100);
168 * Test of a wave moving across the X axis.
170 class TestXPattern extends TestPattern {
171 private final SinLFO xPos = new SinLFO(0, model.xMax, 4000);
172 public TestXPattern(GLucose glucose) {
174 addModulator(xPos).trigger();
176 public void run(double deltaMs) {
177 float hv = lx.getBaseHuef();
178 for (Point p : model.points) {
179 // This is a common technique for modulating brightness.
180 // You can use abs() to determine the distance between two
181 // values. The further away this point is from an exact
182 // point, the more we decrease its brightness
183 float bv = max(0, 100 - abs(p.x - xPos.getValuef()));
184 colors[p.index] = lx.hsb(hv, 100, bv);
190 * Test of a wave on the Y axis.
192 class TestYPattern extends TestPattern {
193 private final SinLFO yPos = new SinLFO(0, model.yMax, 4000);
194 public TestYPattern(GLucose glucose) {
196 addModulator(yPos).trigger();
198 public void run(double deltaMs) {
199 float hv = lx.getBaseHuef();
200 for (Point p : model.points) {
201 float bv = max(0, 100 - abs(p.y - yPos.getValuef()));
202 colors[p.index] = lx.hsb(hv, 100, bv);
208 * Test of a wave on the Z axis.
210 class TestZPattern extends TestPattern {
211 private final SinLFO zPos = new SinLFO(0, model.zMax, 4000);
212 public TestZPattern(GLucose glucose) {
214 addModulator(zPos).trigger();
216 public void run(double deltaMs) {
217 float hv = lx.getBaseHuef();
218 for (Point p : model.points) {
219 float bv = max(0, 100 - abs(p.z - zPos.getValuef()));
220 colors[p.index] = lx.hsb(hv, 100, bv);
226 * This shows how to iterate over towers, enumerated in the model.
228 class TestTowerPattern extends TestPattern {
229 private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size());
231 public TestTowerPattern(GLucose glucose) {
233 addModulator(towerIndex).trigger();
236 public void run(double deltaMs) {
238 for (Tower t : model.towers) {
239 for (Point p : t.points) {
240 colors[p.index] = lx.hsb(
243 max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size()))
253 * This is a demonstration of how to use the projection library. A projection
254 * creates a mutation of the coordinates of all the points in the model, creating
255 * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
256 * art car. However, since in reality the car does not move, the result is that
257 * it appears that the object we are drawing on the car is actually moving.
259 * Keep in mind that what we are creating a projection of is the view coordinates.
260 * Depending on your intuition, some operations may feel backwards. For instance,
261 * if you translate the view to the right, it will make it seem that the object
262 * you are drawing has moved to the left. If you scale the view up 2x, objects
263 * drawn with the same absolute values will seem to be half the size.
265 * If this feels counterintuitive at first, don't worry. Just remember that you
266 * are moving the pixels, not the structure. We're dealing with a finite set
267 * of sparse, non-uniformly spaced pixels. Mutating the structure would move
268 * things to a space where there are no pixels in 99% of the cases.
270 class TestProjectionPattern extends TestPattern {
272 private final Projection projection;
273 private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
274 private final SinLFO yPos = new SinLFO(-20, 40, 5000);
276 public TestProjectionPattern(GLucose glucose) {
278 projection = new Projection(model);
279 addModulator(angle).trigger();
280 addModulator(yPos).trigger();
283 public void run(double deltaMs) {
284 // For the same reasons described above, it may logically feel to you that
285 // some of these operations are in reverse order. Again, just keep in mind that
286 // the car itself is what's moving, not the object
287 projection.reset(model)
289 // Translate so the center of the car is the origin, offset by yPos
290 .translateCenter(model, 0, yPos.getValuef(), 0)
292 // Rotate around the origin (now the center of the car) about an X-vector
293 .rotate(angle.getValuef(), 1, 0, 0)
295 // Scale up the Y axis (objects will look smaller in that access)
298 float hv = lx.getBaseHuef();
299 for (Coord c : projection) {
300 float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
301 // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
302 d = max(0, abs(c.y) - 10 + .1*abs(c.z) + .02*abs(c.x)); // plane / spear thing
303 colors[c.index] = lx.hsb(
304 (hv + .6*abs(c.x) + abs(c.z)) % 360,
306 constrain(140 - 40*d, 0, 100)
312 class TestCubePattern extends TestPattern {
314 private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60);
316 TestCubePattern(GLucose glucose) {
318 addModulator(index).start();
321 public void run(double deltaMs) {
322 for (Cube c : model.cubes) {
324 for (Point p : c.points) {
325 colors[p.index] = lx.hsb(
328 max(0, 100 - 80.*abs(i - index.getValuef()))
336 class MappingTool extends TestPattern {
338 private int cubeIndex = 0;
339 private int stripIndex = 0;
340 private int channelIndex = 0;
342 public final int MAPPING_MODE_ALL = 0;
343 public final int MAPPING_MODE_CHANNEL = 1;
344 public final int MAPPING_MODE_SINGLE_CUBE = 2;
345 public int mappingMode = MAPPING_MODE_ALL;
347 public final int CUBE_MODE_ALL = 0;
348 public final int CUBE_MODE_SINGLE_STRIP = 1;
349 public final int CUBE_MODE_STRIP_PATTERN = 2;
350 public int cubeMode = CUBE_MODE_ALL;
352 public boolean channelModeRed = true;
353 public boolean channelModeGreen = false;
354 public boolean channelModeBlue = false;
356 private final int numChannels;
358 private final PandaMapping[] pandaMappings;
359 private PandaMapping activePanda;
360 private ChannelMapping activeChannel;
362 MappingTool(GLucose glucose, PandaMapping[] pandaMappings) {
364 this.pandaMappings = pandaMappings;
365 numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
369 public int numChannels() {
373 private void setChannel() {
374 activePanda = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD];
375 activeChannel = activePanda.channelList[channelIndex % PandaMapping.CHANNELS_PER_BOARD];
378 private int indexOfCubeInChannel(Cube c) {
379 if (activeChannel.mode == ChannelMapping.MODE_CUBES) {
381 for (int index : activeChannel.objectIndices) {
382 if ((index >= 0) && (c == model.getCubeByRawIndex(index))) {
391 private void printInfo() {
392 println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
395 public void cube(int delta) {
396 int len = model.cubes.size();
397 cubeIndex = (len + cubeIndex + delta) % len;
401 public void strip(int delta) {
402 int len = Cube.STRIPS_PER_CUBE;
403 stripIndex = (len + stripIndex + delta) % len;
407 public void run(double deltaMs) {
413 if (channelModeRed) c |= r;
414 if (channelModeGreen) c |= g;
415 if (channelModeBlue) c |= b;
418 for (Cube cube : model.cubes) {
419 boolean cubeOn = false;
420 int indexOfCubeInChannel = indexOfCubeInChannel(cube);
421 switch (mappingMode) {
422 case MAPPING_MODE_ALL: cubeOn = true; break;
423 case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
424 case MAPPING_MODE_CHANNEL: cubeOn = (indexOfCubeInChannel > 0); break;
427 if (mappingMode == MAPPING_MODE_CHANNEL) {
429 switch (indexOfCubeInChannel) {
430 case 1: cc = r; break;
431 case 2: cc = r|g; break;
432 case 3: cc = g; break;
433 case 4: cc = b; break;
434 case 5: cc = r|b; break;
437 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
440 for (Strip strip : cube.strips) {
441 int faceI = si / Face.STRIPS_PER_FACE;
443 case 0: sc = r; break;
444 case 1: sc = g; break;
445 case 2: sc = b; break;
446 case 3: sc = r|g|b; break;
448 if (si % Face.STRIPS_PER_FACE == 2) {
454 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
456 setColor(cube.strips.get(stripIndex), c);
467 public void setCube(int index) {
468 cubeIndex = index % model.cubes.size();
471 public void incCube() {
472 cubeIndex = (cubeIndex + 1) % model.cubes.size();
475 public void decCube() {
478 cubeIndex += model.cubes.size();
482 public void setChannel(int index) {
483 channelIndex = index % numChannels;
487 public void incChannel() {
488 channelIndex = (channelIndex + 1) % numChannels;
492 public void decChannel() {
493 channelIndex = (channelIndex + numChannels - 1) % numChannels;
497 public void setStrip(int index) {
498 stripIndex = index % Cube.STRIPS_PER_CUBE;
501 public void incStrip() {
502 stripIndex = (stripIndex + 1) % Cube.STRIPS_PER_CUBE;
505 public void decStrip() {
506 stripIndex = (stripIndex + Cube.STRIPS_PER_CUBE - 1) % Cube.STRIPS_PER_CUBE;
509 public void keyPressed(UIMapping uiMapping) {
511 case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break;
512 case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break;
513 case LEFT: decStrip(); break;
514 case RIGHT: incStrip(); break;
517 case 'r': channelModeRed = !channelModeRed; break;
518 case 'g': channelModeGreen = !channelModeGreen; break;
519 case 'b': channelModeBlue = !channelModeBlue; break;
521 uiMapping.setChannelID(channelIndex+1);
522 uiMapping.setCubeID(cubeIndex+1);
523 uiMapping.setStripID(stripIndex+1);