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] = color(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] = color(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] = color(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] = color(h, 100, b);
87 class TestStripPattern extends TestPattern {
89 SinLFO d = new SinLFO(4, 40, 4000);
91 public TestStripPattern(GLucose glucose) {
93 addModulator(d).trigger();
96 public void run(double deltaMs) {
97 for (Strip s : model.strips) {
98 for (Point p : s.points) {
99 colors[p.index] = color(
102 max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy))
110 * Simplest demonstration of using the rotating master hue.
111 * All pixels are full-on the same color.
113 class TestHuePattern extends TestPattern {
114 public TestHuePattern(GLucose glucose) {
118 public void run(double deltaMs) {
119 // Access the core master hue via this method call
120 float hv = lx.getBaseHuef();
121 for (int i = 0; i < colors.length; ++i) {
122 colors[i] = color(hv, 100, 100);
128 * Test of a wave moving across the X axis.
130 class TestXPattern extends TestPattern {
131 private final SinLFO xPos = new SinLFO(0, model.xMax, 4000);
132 public TestXPattern(GLucose glucose) {
134 addModulator(xPos).trigger();
136 public void run(double deltaMs) {
137 float hv = lx.getBaseHuef();
138 for (Point p : model.points) {
139 // This is a common technique for modulating brightness.
140 // You can use abs() to determine the distance between two
141 // values. The further away this point is from an exact
142 // point, the more we decrease its brightness
143 float bv = max(0, 100 - abs(p.fx - xPos.getValuef()));
144 colors[p.index] = color(hv, 100, bv);
150 * Test of a wave on the Y axis.
152 class TestYPattern extends TestPattern {
153 private final SinLFO yPos = new SinLFO(0, model.yMax, 4000);
154 public TestYPattern(GLucose glucose) {
156 addModulator(yPos).trigger();
158 public void run(double deltaMs) {
159 float hv = lx.getBaseHuef();
160 for (Point p : model.points) {
161 float bv = max(0, 100 - abs(p.fy - yPos.getValuef()));
162 colors[p.index] = color(hv, 100, bv);
168 * Test of a wave on the Z axis.
170 class TestZPattern extends TestPattern {
171 private final SinLFO zPos = new SinLFO(0, model.zMax, 4000);
172 public TestZPattern(GLucose glucose) {
174 addModulator(zPos).trigger();
176 public void run(double deltaMs) {
177 float hv = lx.getBaseHuef();
178 for (Point p : model.points) {
179 float bv = max(0, 100 - abs(p.fz - zPos.getValuef()));
180 colors[p.index] = color(hv, 100, bv);
186 * This shows how to iterate over towers, enumerated in the model.
188 class TestTowerPattern extends TestPattern {
189 private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size());
191 public TestTowerPattern(GLucose glucose) {
193 addModulator(towerIndex).trigger();
196 public void run(double deltaMs) {
198 for (Tower t : model.towers) {
199 for (Point p : t.points) {
200 colors[p.index] = color(
203 max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size()))
213 * This is a demonstration of how to use the projection library. A projection
214 * creates a mutation of the coordinates of all the points in the model, creating
215 * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
216 * art car. However, since in reality the car does not move, the result is that
217 * it appears that the object we are drawing on the car is actually moving.
219 * Keep in mind that what we are creating a projection of is the view coordinates.
220 * Depending on your intuition, some operations may feel backwards. For instance,
221 * if you translate the view to the right, it will make it seem that the object
222 * you are drawing has moved to the left. If you scale the view up 2x, objects
223 * drawn with the same absolute values will seem to be half the size.
225 * If this feels counterintuitive at first, don't worry. Just remember that you
226 * are moving the pixels, not the structure. We're dealing with a finite set
227 * of sparse, non-uniformly spaced pixels. Mutating the structure would move
228 * things to a space where there are no pixels in 99% of the cases.
230 class TestProjectionPattern extends TestPattern {
232 private final Projection projection;
233 private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
234 private final SinLFO yPos = new SinLFO(-20, 40, 5000);
236 public TestProjectionPattern(GLucose glucose) {
238 projection = new Projection(model);
239 addModulator(angle).trigger();
240 addModulator(yPos).trigger();
243 public void run(double deltaMs) {
244 // For the same reasons described above, it may logically feel to you that
245 // some of these operations are in reverse order. Again, just keep in mind that
246 // the car itself is what's moving, not the object
247 projection.reset(model)
249 // Translate so the center of the car is the origin, offset by yPos
250 .translateCenter(model, 0, yPos.getValuef(), 0)
252 // Rotate around the origin (now the center of the car) about an X-vector
253 .rotate(angle.getValuef(), 1, 0, 0)
255 // Scale up the Y axis (objects will look smaller in that access)
258 float hv = lx.getBaseHuef();
259 for (Coord c : projection) {
260 float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
261 // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
262 d = max(0, abs(c.y) - 10 + .1*abs(c.z) + .02*abs(c.x)); // plane / spear thing
263 colors[c.index] = color(
264 (hv + .6*abs(c.x) + abs(c.z)) % 360,
266 constrain(140 - 40*d, 0, 100)
272 class TestCubePattern extends TestPattern {
274 private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60);
276 TestCubePattern(GLucose glucose) {
278 addModulator(index).start();
281 public void run(double deltaMs) {
282 for (Cube c : model.cubes) {
284 for (Point p : c.points) {
285 colors[p.index] = color(
288 max(0, 100 - 80.*abs(i - index.getValuef()))
296 class MappingTool extends TestPattern {
298 private int cubeIndex = 0;
299 private int stripIndex = 0;
300 private int channelIndex = 0;
302 public final int MAPPING_MODE_ALL = 0;
303 public final int MAPPING_MODE_CHANNEL = 1;
304 public final int MAPPING_MODE_SINGLE_CUBE = 2;
305 public int mappingMode = MAPPING_MODE_ALL;
307 public final int CUBE_MODE_ALL = 0;
308 public final int CUBE_MODE_SINGLE_STRIP = 1;
309 public final int CUBE_MODE_STRIP_PATTERN = 2;
310 public int cubeMode = CUBE_MODE_ALL;
312 public boolean channelModeRed = true;
313 public boolean channelModeGreen = false;
314 public boolean channelModeBlue = false;
316 private final int numChannels;
318 private final PandaMapping[] pandaMappings;
319 private PandaMapping activePanda;
320 private ChannelMapping activeChannel;
322 MappingTool(GLucose glucose, PandaMapping[] pandaMappings) {
324 this.pandaMappings = pandaMappings;
325 numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
329 public int numChannels() {
333 private void setChannel() {
334 activePanda = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD];
335 activeChannel = activePanda.channelList[channelIndex % PandaMapping.CHANNELS_PER_BOARD];
338 private int indexOfCubeInChannel(Cube c) {
339 if (activeChannel.mode == ChannelMapping.MODE_CUBES) {
341 for (int index : activeChannel.objectIndices) {
342 if ((index >= 0) && (c == model.getCubeByRawIndex(index))) {
351 private void printInfo() {
352 println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
355 public void cube(int delta) {
356 int len = model.cubes.size();
357 cubeIndex = (len + cubeIndex + delta) % len;
361 public void strip(int delta) {
362 int len = Cube.STRIPS_PER_CUBE;
363 stripIndex = (len + stripIndex + delta) % len;
367 public void run(double deltaMs) {
368 color off = color(0, 0, 0);
373 if (channelModeRed) c |= r;
374 if (channelModeGreen) c |= g;
375 if (channelModeBlue) c |= b;
378 for (Cube cube : model.cubes) {
379 boolean cubeOn = false;
380 int indexOfCubeInChannel = indexOfCubeInChannel(cube);
381 switch (mappingMode) {
382 case MAPPING_MODE_ALL: cubeOn = true; break;
383 case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
384 case MAPPING_MODE_CHANNEL: cubeOn = (indexOfCubeInChannel > 0); break;
387 if (mappingMode == MAPPING_MODE_CHANNEL) {
389 switch (indexOfCubeInChannel) {
390 case 1: cc = r; break;
391 case 2: cc = r|g; break;
392 case 3: cc = g; break;
393 case 4: cc = b; break;
394 case 5: cc = r|b; break;
397 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
400 for (Strip strip : cube.strips) {
401 int faceI = si / Face.STRIPS_PER_FACE;
403 case 0: sc = r; break;
404 case 1: sc = g; break;
405 case 2: sc = b; break;
406 case 3: sc = r|g|b; break;
408 if (si % Face.STRIPS_PER_FACE == 2) {
414 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
416 setColor(cube.strips.get(stripIndex), c);
427 public void setCube(int index) {
428 cubeIndex = index % model.cubes.size();
431 public void incCube() {
432 cubeIndex = (cubeIndex + 1) % model.cubes.size();
435 public void decCube() {
438 cubeIndex += model.cubes.size();
442 public void setChannel(int index) {
443 channelIndex = index % numChannels;
447 public void incChannel() {
448 channelIndex = (channelIndex + 1) % numChannels;
452 public void decChannel() {
453 channelIndex = (channelIndex + numChannels - 1) % numChannels;
457 public void setStrip(int index) {
458 stripIndex = index % Cube.STRIPS_PER_CUBE;
461 public void incStrip() {
462 stripIndex = (stripIndex + 1) % Cube.STRIPS_PER_CUBE;
465 public void decStrip() {
466 stripIndex = (stripIndex + Cube.STRIPS_PER_CUBE - 1) % Cube.STRIPS_PER_CUBE;
469 public void keyPressed(UIMapping uiMapping) {
471 case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break;
472 case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break;
473 case LEFT: decStrip(); break;
474 case RIGHT: incStrip(); break;
477 case 'r': channelModeRed = !channelModeRed; break;
478 case 'g': channelModeGreen = !channelModeGreen; break;
479 case 'b': channelModeBlue = !channelModeBlue; break;
481 uiMapping.setChannelID(channelIndex+1);
482 uiMapping.setCubeID(cubeIndex+1);
483 uiMapping.setStripID(stripIndex+1);