2 * Simplest demonstration of using the rotating master hue.
3 * All pixels are full-on the same color.
5 class TestHuePattern extends SCPattern {
6 public TestHuePattern(GLucose glucose) {
10 public void run(int deltaMs) {
11 // Access the core master hue via this method call
12 float hv = lx.getBaseHuef();
13 for (int i = 0; i < colors.length; ++i) {
14 colors[i] = color(hv, 100, 100);
20 * Test of a wave moving across the X axis.
22 class TestXPattern extends SCPattern {
23 private final SinLFO xPos = new SinLFO(0, model.xMax, 4000);
24 public TestXPattern(GLucose glucose) {
26 addModulator(xPos).trigger();
28 public void run(int deltaMs) {
29 float hv = lx.getBaseHuef();
30 for (Point p : model.points) {
31 // This is a common technique for modulating brightness.
32 // You can use abs() to determine the distance between two
33 // values. The further away this point is from an exact
34 // point, the more we decrease its brightness
35 float bv = max(0, 100 - abs(p.fx - xPos.getValuef()));
36 colors[p.index] = color(hv, 100, bv);
42 * Test of a wave on the Y axis.
44 class TestYPattern extends SCPattern {
45 private final SinLFO yPos = new SinLFO(0, model.yMax, 4000);
46 public TestYPattern(GLucose glucose) {
48 addModulator(yPos).trigger();
50 public void run(int deltaMs) {
51 float hv = lx.getBaseHuef();
52 for (Point p : model.points) {
53 float bv = max(0, 100 - abs(p.fy - yPos.getValuef()));
54 colors[p.index] = color(hv, 100, bv);
60 * Test of a wave on the Z axis.
62 class TestZPattern extends SCPattern {
63 private final SinLFO zPos = new SinLFO(0, model.zMax, 4000);
64 public TestZPattern(GLucose glucose) {
66 addModulator(zPos).trigger();
68 public void run(int deltaMs) {
69 float hv = lx.getBaseHuef();
70 for (Point p : model.points) {
71 float bv = max(0, 100 - abs(p.fz - zPos.getValuef()));
72 colors[p.index] = color(hv, 100, bv);
78 * This shows how to iterate over towers, enumerated in the model.
80 class TestTowerPattern extends SCPattern {
81 private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size());
83 public TestTowerPattern(GLucose glucose) {
85 addModulator(towerIndex).trigger();
88 public void run(int deltaMs) {
90 for (Tower t : model.towers) {
91 for (Point p : t.points) {
92 colors[p.index] = color(
95 max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size()))
105 * This is a demonstration of how to use the projection library. A projection
106 * creates a mutation of the coordinates of all the points in the model, creating
107 * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
108 * art car. However, since in reality the car does not move, the result is that
109 * it appears that the object we are drawing on the car is actually moving.
111 * Keep in mind that what we are creating a projection of is the view coordinates.
112 * Depending on your intuition, some operations may feel backwards. For instance,
113 * if you translate the view to the right, it will make it seem that the object
114 * you are drawing has moved to the left. If you scale the view up 2x, objects
115 * drawn with the same absolute values will seem to be half the size.
117 * If this feels counterintuitive at first, don't worry. Just remember that you
118 * are moving the pixels, not the structure. We're dealing with a finite set
119 * of sparse, non-uniformly spaced pixels. Mutating the structure would move
120 * things to a space where there are no pixels in 99% of the cases.
122 class TestProjectionPattern extends SCPattern {
124 private final Projection projection;
125 private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
126 private final SinLFO yPos = new SinLFO(-20, 40, 5000);
128 public TestProjectionPattern(GLucose glucose) {
130 projection = new Projection(model);
131 addModulator(angle).trigger();
132 addModulator(yPos).trigger();
135 public void run(int deltaMs) {
136 // For the same reasons described above, it may logically feel to you that
137 // some of these operations are in reverse order. Again, just keep in mind that
138 // the car itself is what's moving, not the object
139 projection.reset(model)
141 // Translate so the center of the car is the origin, offset by yPos
142 .translateCenter(model, 0, yPos.getValuef(), 0)
144 // Rotate around the origin (now the center of the car) about an X-vector
145 .rotate(angle.getValuef(), 1, 0, 0)
147 // Scale up the Y axis (objects will look smaller in that access)
150 float hv = lx.getBaseHuef();
151 for (Coord c : projection) {
152 float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
153 // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
154 d = max(0, abs(c.y) - 10 + .3*abs(c.z) + .08*abs(c.x)); // plane / spear thing
155 colors[c.index] = color(
156 (hv + .6*abs(c.x) + abs(c.z)) % 360,
158 constrain(140 - 10*d, 0, 100)
164 class TestCubePattern extends SCPattern {
166 private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60);
168 TestCubePattern(GLucose glucose) {
170 addModulator(index).start();
173 public void run(int deltaMs) {
174 for (Cube c : model.cubes) {
176 for (Point p : c.points) {
177 colors[p.index] = color(
180 max(0, 100 - 80.*abs(i - index.getValuef()))
188 class MappingTool extends SCPattern {
190 private int cubeIndex = 0;
191 private int stripIndex = 0;
192 private int channelIndex = 0;
194 public final int MAPPING_MODE_ALL = 0;
195 public final int MAPPING_MODE_CHANNEL = 1;
196 public final int MAPPING_MODE_SINGLE_CUBE = 2;
197 public int mappingMode = MAPPING_MODE_ALL;
199 public final int CUBE_MODE_ALL = 0;
200 public final int CUBE_MODE_SINGLE_STRIP = 1;
201 public final int CUBE_MODE_STRIP_PATTERN = 2;
202 public int cubeMode = CUBE_MODE_ALL;
204 public boolean channelModeRed = true;
205 public boolean channelModeGreen = false;
206 public boolean channelModeBlue = false;
208 private final int numChannels;
210 private final PandaMapping[] pandaMappings;
211 private PandaMapping activeMapping;
212 private int mappingChannelIndex;
214 MappingTool(GLucose glucose, PandaMapping[] pandaMappings) {
216 this.pandaMappings = pandaMappings;
217 numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
221 private void setChannel() {
222 mappingChannelIndex = channelIndex % PandaMapping.CHANNELS_PER_BOARD;
223 activeMapping = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD];
226 private int cubeInChannel(Cube c) {
228 for (int index : activeMapping.channelList[mappingChannelIndex]) {
229 if (c == model.getCubeByRawIndex(index)) {
237 private void printInfo() {
238 println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
241 public void cube(int delta) {
242 int len = model.cubes.size();
243 cubeIndex = (len + cubeIndex + delta) % len;
247 public void strip(int delta) {
248 int len = Cube.STRIPS_PER_CUBE;
249 stripIndex = (len + stripIndex + delta) % len;
253 public void run(int deltaMs) {
254 color off = color(0, 0, 0);
259 if (channelModeRed) c |= r;
260 if (channelModeGreen) c |= g;
261 if (channelModeBlue) c |= b;
264 for (Cube cube : model.cubes) {
265 boolean cubeOn = false;
266 int channelIndex = cubeInChannel(cube);
267 switch (mappingMode) {
268 case MAPPING_MODE_ALL: cubeOn = true; break;
269 case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
270 case MAPPING_MODE_CHANNEL: cubeOn = (channelIndex > 0); break;
273 if (mappingMode == MAPPING_MODE_CHANNEL) {
275 switch (channelIndex) {
276 case 1: cc = r; break;
277 case 2: cc = r|g; break;
278 case 3: cc = g; break;
279 case 4: cc = b; break;
280 case 5: cc = r|b; break;
283 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
286 for (Strip strip : cube.strips) {
287 int faceI = si / Face.STRIPS_PER_FACE;
289 case 0: sc = r; break;
290 case 1: sc = g; break;
291 case 2: sc = b; break;
292 case 3: sc = r|g|b; break;
294 if (si % Face.STRIPS_PER_FACE == 2) {
300 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
302 setColor(cube.strips.get(stripIndex), c);
314 public void incCube() {
315 cubeIndex = (cubeIndex + 1) % model.cubes.size();
318 public void decCube() {
321 cubeIndex += model.cubes.size();
325 public void incChannel() {
326 channelIndex = (channelIndex + 1) % numChannels;
330 public void decChannel() {
332 if (channelIndex < 0) {
333 channelIndex += numChannels;
338 public void incStrip() {
339 int stripsPerCube = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE;
340 stripIndex = (stripIndex + 1) % stripsPerCube;
343 public void decStrip() {
344 int stripsPerCube = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE;
346 if (stripIndex < 0) {
347 stripIndex += stripsPerCube;
351 public void keyPressed() {
353 case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break;
354 case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break;
355 case LEFT: decStrip(); break;
356 case RIGHT: incStrip(); break;
359 case 'r': channelModeRed = !channelModeRed; break;
360 case 'g': channelModeGreen = !channelModeGreen; break;
361 case 'b': channelModeBlue = !channelModeBlue; break;