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 is a demonstration of how to use the projection library. A projection
79 * creates a mutation of the coordinates of all the points in the model, creating
80 * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
81 * art car. However, since in reality the car does not move, the result is that
82 * it appears that the object we are drawing on the car is actually moving.
84 * Keep in mind that what we are creating a projection of is the view coordinates.
85 * Depending on your intuition, some operations may feel backwards. For instance,
86 * if you translate the view to the right, it will make it seem that the object
87 * you are drawing has moved to the left. If you scale the view up 2x, objects
88 * drawn with the same absolute values will seem to be half the size.
90 * If this feels counterintuitive at first, don't worry. Just remember that you
91 * are moving the pixels, not the structure. We're dealing with a finite set
92 * of sparse, non-uniformly spaced pixels. Mutating the structure would move
93 * things to a space where there are no pixels in 99% of the cases.
95 class TestProjectionPattern extends SCPattern {
97 private final Projection projection;
98 private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
99 private final SinLFO yPos = new SinLFO(-20, 40, 5000);
101 public TestProjectionPattern(GLucose glucose) {
103 projection = new Projection(model);
104 addModulator(angle).trigger();
105 addModulator(yPos).trigger();
108 public void run(int deltaMs) {
109 // For the same reasons described above, it may logically feel to you that
110 // some of these operations are in reverse order. Again, just keep in mind that
111 // the car itself is what's moving, not the object
112 projection.reset(model)
114 // Translate so the center of the car is the origin, offset by yPos
115 .translateCenter(0, yPos.getValuef(), 0)
117 // Rotate around the origin (now the center of the car) about an X-vector
118 .rotate(angle.getValuef(), 1, 0, 0)
120 // Scale up the Y axis (objects will look smaller in that access)
123 float hv = lx.getBaseHuef();
124 for (Coord c : projection) {
125 float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
126 // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
127 d = max(0, abs(c.y) - 10 + .3*abs(c.z) + .08*abs(c.x)); // plane / spear thing
128 colors[c.index] = color(
129 (hv + .6*abs(c.x) + abs(c.z)) % 360,
131 constrain(140 - 10*d, 0, 100)
137 class MappingTool extends SCPattern {
139 private int cubeIndex = 0;
140 private int stripIndex = 0;
141 private int channelIndex = 0;
143 public final int MAPPING_MODE_ALL = 0;
144 public final int MAPPING_MODE_CHANNEL = 1;
145 public final int MAPPING_MODE_SINGLE_CUBE = 2;
146 public int mappingMode = MAPPING_MODE_ALL;
148 public final int CUBE_MODE_ALL = 0;
149 public final int CUBE_MODE_SINGLE_STRIP = 1;
150 public final int CUBE_MODE_STRIP_PATTERN = 2;
151 public int cubeMode = CUBE_MODE_ALL;
153 public boolean channelModeRed = true;
154 public boolean channelModeGreen = false;
155 public boolean channelModeBlue = false;
157 private final static int NUM_CHANNELS = 16;
159 private final int[][] frontChannels;
160 private final int[][] rearChannels;
161 private int[] activeChannels;
163 MappingTool(GLucose glucose, int[][]frontChannels, int[][]rearChannels) {
165 this.frontChannels = frontChannels;
166 this.rearChannels = rearChannels;
170 private void setChannel() {
171 if (channelIndex < frontChannels.length) {
172 activeChannels = frontChannels[channelIndex];
174 activeChannels = rearChannels[channelIndex - frontChannels.length];
178 private int cubeInChannel(Cube c) {
180 for (int index : activeChannels) {
181 if (c == model.getCubeByRawIndex(index)) {
189 private void printInfo() {
190 println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
193 public void cube(int delta) {
194 int len = model.cubes.size();
195 cubeIndex = (len + cubeIndex + delta) % len;
199 public void strip(int delta) {
200 int len = Cube.CLIPS_PER_CUBE * Clip.STRIPS_PER_CLIP;
201 stripIndex = (len + stripIndex + delta) % len;
205 public void run(int deltaMs) {
206 color off = color(0, 0, 0);
211 if (channelModeRed) c |= r;
212 if (channelModeGreen) c |= g;
213 if (channelModeBlue) c |= b;
216 for (Cube cube : model.cubes) {
217 boolean cubeOn = false;
218 int channelIndex = cubeInChannel(cube);
219 switch (mappingMode) {
220 case MAPPING_MODE_ALL: cubeOn = true; break;
221 case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
222 case MAPPING_MODE_CHANNEL: cubeOn = (channelIndex > 0); break;
225 if (mappingMode == MAPPING_MODE_CHANNEL) {
227 switch (channelIndex) {
228 case 1: cc = r; break;
229 case 2: cc = r|g; break;
230 case 3: cc = g; break;
231 case 4: cc = b; break;
232 case 5: cc = r|b; break;
235 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
238 for (Strip strip : cube.strips) {
239 int clipI = si / Clip.STRIPS_PER_CLIP;
241 case 0: sc = r; break;
242 case 1: sc = g; break;
243 case 2: sc = b; break;
244 case 3: sc = r|g|b; break;
246 if (si % Clip.STRIPS_PER_CLIP == 2) {
252 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
254 setColor(cube.strips.get(stripIndex), c);
266 public void incCube() {
267 cubeIndex = (cubeIndex + 1) % model.cubes.size();
270 public void decCube() {
273 cubeIndex += model.cubes.size();
277 public void incChannel() {
278 channelIndex = (channelIndex + 1) % NUM_CHANNELS;
282 public void decChannel() {
284 if (channelIndex < 0) {
285 channelIndex += NUM_CHANNELS;
290 public void incStrip() {
291 int stripsPerCube = Cube.CLIPS_PER_CUBE * Clip.STRIPS_PER_CLIP;
292 stripIndex = (stripIndex + 1) % stripsPerCube;
295 public void decStrip() {
296 int stripsPerCube = Cube.CLIPS_PER_CUBE * Clip.STRIPS_PER_CLIP;
298 if (stripIndex < 0) {
299 stripIndex += stripsPerCube;
303 public void keyPressed() {
305 case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break;
306 case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break;
307 case LEFT: decStrip(); break;
308 case RIGHT: incStrip(); break;
311 case 'r': channelModeRed = !channelModeRed; break;
312 case 'g': channelModeGreen = !channelModeGreen; break;
313 case 'b': channelModeBlue = !channelModeBlue; break;