1 class BlankPattern extends SCPattern {
6 public void run(double deltaMs) {
11 abstract class TestPattern extends SCPattern {
12 public TestPattern(LX lx) {
18 class TestStripPattern extends TestPattern {
20 SinLFO d = new SinLFO(4, 40, 4000);
22 public TestStripPattern(LX lx) {
24 addModulator(d).trigger();
27 public void run(double deltaMs) {
28 for (Strip s : model.strips) {
29 for (LXPoint p : s.points) {
30 colors[p.index] = lx.hsb(
33 max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy))
41 * Simplest demonstration of using the rotating master hue.
42 * All pixels are full-on the same color.
44 class TestHuePattern extends TestPattern {
45 public TestHuePattern(LX lx) {
49 public void run(double deltaMs) {
50 // Access the core master hue via this method call
51 float hv = lx.getBaseHuef();
52 for (int i = 0; i < colors.length; ++i) {
53 colors[i] = lx.hsb(hv, 100, 100);
59 * Test of a wave moving across the X axis.
61 class TestXPattern extends TestPattern {
62 private final SinLFO xPos = new SinLFO(0, model.xMax, 4000);
63 public TestXPattern(LX lx) {
65 addModulator(xPos).trigger();
67 public void run(double deltaMs) {
68 float hv = lx.getBaseHuef();
69 for (LXPoint p : model.points) {
70 // This is a common technique for modulating brightness.
71 // You can use abs() to determine the distance between two
72 // values. The further away this point is from an exact
73 // point, the more we decrease its brightness
74 float bv = max(0, 100 - abs(p.x - xPos.getValuef()));
75 colors[p.index] = lx.hsb(hv, 100, bv);
81 * Test of a wave on the Y axis.
83 class TestYPattern extends TestPattern {
84 private final SinLFO yPos = new SinLFO(0, model.yMax, 4000);
85 public TestYPattern(LX lx) {
87 addModulator(yPos).trigger();
89 public void run(double deltaMs) {
90 float hv = lx.getBaseHuef();
91 for (LXPoint p : model.points) {
92 float bv = max(0, 100 - abs(p.y - yPos.getValuef()));
93 colors[p.index] = lx.hsb(hv, 100, bv);
99 * Test of a wave on the Z axis.
101 class TestZPattern extends TestPattern {
102 private final SinLFO zPos = new SinLFO(0, model.zMax, 4000);
103 public TestZPattern(LX lx) {
105 addModulator(zPos).trigger();
107 public void run(double deltaMs) {
108 float hv = lx.getBaseHuef();
109 for (LXPoint p : model.points) {
110 float bv = max(0, 100 - abs(p.z - zPos.getValuef()));
111 colors[p.index] = lx.hsb(hv, 100, bv);
117 * This shows how to iterate over towers, enumerated in the model.
119 class TestTowerPattern extends TestPattern {
120 private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size());
122 public TestTowerPattern(LX lx) {
124 addModulator(towerIndex).trigger();
127 public void run(double deltaMs) {
129 for (Tower t : model.towers) {
130 for (LXPoint p : t.points) {
131 colors[p.index] = lx.hsb(
134 max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size()))
144 * This is a demonstration of how to use the projection library. A projection
145 * creates a mutation of the coordinates of all the points in the model, creating
146 * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire
147 * art car. However, since in reality the car does not move, the result is that
148 * it appears that the object we are drawing on the car is actually moving.
150 * Keep in mind that what we are creating a projection of is the view coordinates.
151 * Depending on your intuition, some operations may feel backwards. For instance,
152 * if you translate the view to the right, it will make it seem that the object
153 * you are drawing has moved to the left. If you scale the view up 2x, objects
154 * drawn with the same absolute values will seem to be half the size.
156 * If this feels counterintuitive at first, don't worry. Just remember that you
157 * are moving the pixels, not the structure. We're dealing with a finite set
158 * of sparse, non-uniformly spaced pixels. Mutating the structure would move
159 * things to a space where there are no pixels in 99% of the cases.
161 class TestProjectionPattern extends TestPattern {
163 private final LXProjection projection;
164 private final SawLFO angle = new SawLFO(0, TWO_PI, 9000);
165 private final SinLFO yPos = new SinLFO(-20, 40, 5000);
167 public TestProjectionPattern(LX lx) {
169 projection = new LXProjection(model);
170 addModulator(angle).trigger();
171 addModulator(yPos).trigger();
174 public void run(double deltaMs) {
175 // For the same reasons described above, it may logically feel to you that
176 // some of these operations are in reverse order. Again, just keep in mind that
177 // the car itself is what's moving, not the object
180 // Translate so the center of the car is the origin, offset by yPos
181 .translateCenter(0, yPos.getValuef(), 0)
183 // Rotate around the origin (now the center of the car) about an X-vector
184 .rotate(angle.getValuef(), 1, 0, 0)
186 // Scale up the Y axis (objects will look smaller in that access)
189 float hv = lx.getBaseHuef();
190 for (LXVector c : projection) {
191 float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin
192 // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing
193 d = max(0, abs(c.y) - 10 + .1*abs(c.z) + .02*abs(c.x)); // plane / spear thing
194 colors[c.index] = lx.hsb(
195 (hv + .6*abs(c.x) + abs(c.z)) % 360,
197 constrain(140 - 40*d, 0, 100)
203 class TestCubePattern extends TestPattern {
205 private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60);
207 TestCubePattern(LX lx) {
209 addModulator(index).start();
212 public void run(double deltaMs) {
213 for (Cube c : model.cubes) {
215 for (LXPoint p : c.points) {
216 colors[p.index] = lx.hsb(
219 max(0, 100 - 80.*abs(i - index.getValuef()))
227 class MappingTool extends TestPattern {
229 private int cubeIndex = 0;
230 private int stripIndex = 0;
232 public final int MAPPING_MODE_ALL = 0;
233 public final int MAPPING_MODE_CHANNEL = 1;
234 public final int MAPPING_MODE_SINGLE_CUBE = 2;
235 public int mappingMode = MAPPING_MODE_ALL;
237 public final int CUBE_MODE_ALL = 0;
238 public final int CUBE_MODE_SINGLE_STRIP = 1;
239 public final int CUBE_MODE_STRIP_PATTERN = 2;
240 public int cubeMode = CUBE_MODE_ALL;
242 public boolean channelModeRed = true;
243 public boolean channelModeGreen = false;
244 public boolean channelModeBlue = false;
250 private int indexOfCubeInChannel(Cube c) {
251 // TODO(mcslee): port to grizzly
255 private void printInfo() {
256 println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1));
259 public void cube(int delta) {
260 int len = model.cubes.size();
261 cubeIndex = (len + cubeIndex + delta) % len;
265 public void strip(int delta) {
266 int len = Cube.STRIPS_PER_CUBE;
267 stripIndex = (len + stripIndex + delta) % len;
271 public void run(double deltaMs) {
277 if (channelModeRed) c |= r;
278 if (channelModeGreen) c |= g;
279 if (channelModeBlue) c |= b;
282 for (Cube cube : model.cubes) {
283 boolean cubeOn = false;
284 int indexOfCubeInChannel = indexOfCubeInChannel(cube);
285 switch (mappingMode) {
286 case MAPPING_MODE_ALL: cubeOn = true; break;
287 case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break;
288 case MAPPING_MODE_CHANNEL: cubeOn = (indexOfCubeInChannel > 0); break;
291 if (mappingMode == MAPPING_MODE_CHANNEL) {
293 switch (indexOfCubeInChannel) {
294 case 1: cc = r; break;
295 case 2: cc = r|g; break;
296 case 3: cc = g; break;
297 case 4: cc = b; break;
298 case 5: cc = r|b; break;
301 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
304 for (Strip strip : cube.strips) {
305 int faceI = si / Face.STRIPS_PER_FACE;
307 case 0: sc = r; break;
308 case 1: sc = g; break;
309 case 2: sc = b; break;
310 case 3: sc = r|g|b; break;
312 if (si % Face.STRIPS_PER_FACE == 2) {
318 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
320 setColor(cube.strips.get(stripIndex), c);
331 public void setCube(int index) {
332 cubeIndex = index % model.cubes.size();
335 public void incCube() {
336 cubeIndex = (cubeIndex + 1) % model.cubes.size();
339 public void decCube() {
342 cubeIndex += model.cubes.size();
346 public void setStrip(int index) {
347 stripIndex = index % Cube.STRIPS_PER_CUBE;
350 public void incStrip() {
351 stripIndex = (stripIndex + 1) % Cube.STRIPS_PER_CUBE;
354 public void decStrip() {
355 stripIndex = (stripIndex + Cube.STRIPS_PER_CUBE - 1) % Cube.STRIPS_PER_CUBE;
358 public void keyPressed(UIMapping uiMapping) {
360 case UP: incCube(); break;
361 case DOWN: decCube(); break;
362 case LEFT: decStrip(); break;
363 case RIGHT: incStrip(); break;
366 case 'r': channelModeRed = !channelModeRed; break;
367 case 'g': channelModeGreen = !channelModeGreen; break;
368 case 'b': channelModeBlue = !channelModeBlue; break;
370 uiMapping.setCubeID(cubeIndex+1);
371 uiMapping.setStripID(stripIndex+1);