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();
86 towerIndex.setValue(9);
89 public void run(int deltaMs) {
90 println((int)towerIndex.getValuef());
92 for (Tower t : model.towers) {
93 for (Point p : t.points) {
94 colors[p.index] = color(
97 max(0, 100 - 80*abs(ti - towerIndex.getValuef()))
107 * This is a demonstration of how to use the projection library. A projection
108 * creates a mutation of the coordinates of all the points in the model, creating
109 * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
110 * art car. However, since in reality the car does not move, the result is that
111 * it appears that the object we are drawing on the car is actually moving.
113 * Keep in mind that what we are creating a projection of is the view coordinates.
114 * Depending on your intuition, some operations may feel backwards. For instance,
115 * if you translate the view to the right, it will make it seem that the object
116 * you are drawing has moved to the left. If you scale the view up 2x, objects
117 * drawn with the same absolute values will seem to be half the size.
119 * If this feels counterintuitive at first, don't worry. Just remember that you
120 * are moving the pixels, not the structure. We're dealing with a finite set
121 * of sparse, non-uniformly spaced pixels. Mutating the structure would move
122 * things to a space where there are no pixels in 99% of the cases.
124 class TestProjectionPattern extends SCPattern {
126 private final Projection projection;
127 private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
128 private final SinLFO yPos = new SinLFO(-20, 40, 5000);
130 public TestProjectionPattern(GLucose glucose) {
132 projection = new Projection(model);
133 addModulator(angle).trigger();
134 addModulator(yPos).trigger();
137 public void run(int deltaMs) {
138 // For the same reasons described above, it may logically feel to you that
139 // some of these operations are in reverse order. Again, just keep in mind that
140 // the car itself is what's moving, not the object
141 projection.reset(model)
143 // Translate so the center of the car is the origin, offset by yPos
144 .translateCenter(model, 0, yPos.getValuef(), 0)
146 // Rotate around the origin (now the center of the car) about an X-vector
147 .rotate(angle.getValuef(), 1, 0, 0)
149 // Scale up the Y axis (objects will look smaller in that access)
152 float hv = lx.getBaseHuef();
153 for (Coord c : projection) {
154 float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
155 // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
156 d = max(0, abs(c.y) - 10 + .3*abs(c.z) + .08*abs(c.x)); // plane / spear thing
157 colors[c.index] = color(
158 (hv + .6*abs(c.x) + abs(c.z)) % 360,
160 constrain(140 - 10*d, 0, 100)
166 class TestCubePattern extends SCPattern {
168 private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60);
170 TestCubePattern(GLucose glucose) {
172 addModulator(index).start();
175 public void run(int deltaMs) {
176 for (Cube c : model.cubes) {
178 for (Point p : c.points) {
179 colors[p.index] = color(
182 max(0, 100 - 80.*abs(i - index.getValuef()))
190 class MappingTool extends SCPattern {
192 private int cubeIndex = 0;
193 private int stripIndex = 0;
194 private int channelIndex = 0;
196 public final int MAPPING_MODE_ALL = 0;
197 public final int MAPPING_MODE_CHANNEL = 1;
198 public final int MAPPING_MODE_SINGLE_CUBE = 2;
199 public int mappingMode = MAPPING_MODE_ALL;
201 public final int CUBE_MODE_ALL = 0;
202 public final int CUBE_MODE_SINGLE_STRIP = 1;
203 public final int CUBE_MODE_STRIP_PATTERN = 2;
204 public int cubeMode = CUBE_MODE_ALL;
206 public boolean channelModeRed = true;
207 public boolean channelModeGreen = false;
208 public boolean channelModeBlue = false;
210 private final int numChannels;
212 private final PandaMapping[] pandaMappings;
213 private PandaMapping activeMapping;
214 private int mappingChannelIndex;
216 MappingTool(GLucose glucose, PandaMapping[] pandaMappings) {
218 this.pandaMappings = pandaMappings;
219 numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
223 private void setChannel() {
224 mappingChannelIndex = channelIndex % PandaMapping.CHANNELS_PER_BOARD;
225 activeMapping = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD];
228 private int cubeInChannel(Cube c) {
230 for (int index : activeMapping.channelList[mappingChannelIndex]) {
231 if (c == model.getCubeByRawIndex(index)) {
239 private void printInfo() {
240 println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
243 public void cube(int delta) {
244 int len = model.cubes.size();
245 cubeIndex = (len + cubeIndex + delta) % len;
249 public void strip(int delta) {
250 int len = Cube.STRIPS_PER_CUBE;
251 stripIndex = (len + stripIndex + delta) % len;
255 public void run(int deltaMs) {
256 color off = color(0, 0, 0);
261 if (channelModeRed) c |= r;
262 if (channelModeGreen) c |= g;
263 if (channelModeBlue) c |= b;
266 for (Cube cube : model.cubes) {
267 boolean cubeOn = false;
268 int channelIndex = cubeInChannel(cube);
269 switch (mappingMode) {
270 case MAPPING_MODE_ALL: cubeOn = true; break;
271 case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
272 case MAPPING_MODE_CHANNEL: cubeOn = (channelIndex > 0); break;
275 if (mappingMode == MAPPING_MODE_CHANNEL) {
277 switch (channelIndex) {
278 case 1: cc = r; break;
279 case 2: cc = r|g; break;
280 case 3: cc = g; break;
281 case 4: cc = b; break;
282 case 5: cc = r|b; break;
285 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
288 for (Strip strip : cube.strips) {
289 int faceI = si / Face.STRIPS_PER_FACE;
291 case 0: sc = r; break;
292 case 1: sc = g; break;
293 case 2: sc = b; break;
294 case 3: sc = r|g|b; break;
296 if (si % Face.STRIPS_PER_FACE == 2) {
302 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
304 setColor(cube.strips.get(stripIndex), c);
316 public void incCube() {
317 cubeIndex = (cubeIndex + 1) % model.cubes.size();
320 public void decCube() {
323 cubeIndex += model.cubes.size();
327 public void incChannel() {
328 channelIndex = (channelIndex + 1) % numChannels;
332 public void decChannel() {
334 if (channelIndex < 0) {
335 channelIndex += numChannels;
340 public void incStrip() {
341 int stripsPerCube = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE;
342 stripIndex = (stripIndex + 1) % stripsPerCube;
345 public void decStrip() {
346 int stripsPerCube = Cube.FACES_PER_CUBE * Face.STRIPS_PER_FACE;
348 if (stripIndex < 0) {
349 stripIndex += stripsPerCube;
353 public void keyPressed() {
355 case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break;
356 case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break;
357 case LEFT: decStrip(); break;
358 case RIGHT: incStrip(); break;
361 case 'r': channelModeRed = !channelModeRed; break;
362 case 'g': channelModeGreen = !channelModeGreen; break;
363 case 'b': channelModeBlue = !channelModeBlue; break;