]>
Commit | Line | Data |
---|---|---|
1 | class BlankPattern extends SCPattern { | |
2 | BlankPattern(LX lx) { | |
3 | super(lx); | |
4 | } | |
5 | ||
6 | public void run(double deltaMs) { | |
7 | setColors(#000000); | |
8 | } | |
9 | } | |
10 | ||
11 | abstract class TestPattern extends SCPattern { | |
12 | public TestPattern(LX lx) { | |
13 | super(lx); | |
14 | setEligible(false); | |
15 | } | |
16 | } | |
17 | ||
18 | class TestStripPattern extends TestPattern { | |
19 | ||
20 | SinLFO d = new SinLFO(4, 40, 4000); | |
21 | ||
22 | public TestStripPattern(LX lx) { | |
23 | super(lx); | |
24 | addModulator(d).trigger(); | |
25 | } | |
26 | ||
27 | public void run(double deltaMs) { | |
28 | for (Strip s : model.strips) { | |
29 | for (LXPoint p : s.points) { | |
30 | colors[p.index] = lx.hsb( | |
31 | lx.getBaseHuef(), | |
32 | 100, | |
33 | max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy)) | |
34 | ); | |
35 | } | |
36 | } | |
37 | } | |
38 | } | |
39 | ||
40 | /** | |
41 | * Simplest demonstration of using the rotating master hue. | |
42 | * All pixels are full-on the same color. | |
43 | */ | |
44 | class TestHuePattern extends TestPattern { | |
45 | public TestHuePattern(LX lx) { | |
46 | super(lx); | |
47 | } | |
48 | ||
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); | |
54 | } | |
55 | } | |
56 | } | |
57 | ||
58 | /** | |
59 | * Test of a wave moving across the X axis. | |
60 | */ | |
61 | class TestXPattern extends TestPattern { | |
62 | private final SinLFO xPos = new SinLFO(0, model.xMax, 4000); | |
63 | public TestXPattern(LX lx) { | |
64 | super(lx); | |
65 | addModulator(xPos).trigger(); | |
66 | } | |
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); | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | /** | |
81 | * Test of a wave on the Y axis. | |
82 | */ | |
83 | class TestYPattern extends TestPattern { | |
84 | private final SinLFO yPos = new SinLFO(0, model.yMax, 4000); | |
85 | public TestYPattern(LX lx) { | |
86 | super(lx); | |
87 | addModulator(yPos).trigger(); | |
88 | } | |
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); | |
94 | } | |
95 | } | |
96 | } | |
97 | ||
98 | /** | |
99 | * Test of a wave on the Z axis. | |
100 | */ | |
101 | class TestZPattern extends TestPattern { | |
102 | private final SinLFO zPos = new SinLFO(0, model.zMax, 4000); | |
103 | public TestZPattern(LX lx) { | |
104 | super(lx); | |
105 | addModulator(zPos).trigger(); | |
106 | } | |
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); | |
112 | } | |
113 | } | |
114 | } | |
115 | ||
116 | /** | |
117 | * This shows how to iterate over towers, enumerated in the model. | |
118 | */ | |
119 | class TestTowerPattern extends TestPattern { | |
120 | private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size()); | |
121 | ||
122 | public TestTowerPattern(LX lx) { | |
123 | super(lx); | |
124 | addModulator(towerIndex).trigger(); | |
125 | } | |
126 | ||
127 | public void run(double deltaMs) { | |
128 | int ti = 0; | |
129 | for (Tower t : model.towers) { | |
130 | for (LXPoint p : t.points) { | |
131 | colors[p.index] = lx.hsb( | |
132 | lx.getBaseHuef(), | |
133 | 100, | |
134 | max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size())) | |
135 | ); | |
136 | } | |
137 | ++ti; | |
138 | } | |
139 | } | |
140 | ||
141 | } | |
142 | ||
143 | /** | |
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. | |
149 | * | |
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. | |
155 | * | |
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. | |
160 | */ | |
161 | class TestProjectionPattern extends TestPattern { | |
162 | ||
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); | |
166 | ||
167 | public TestProjectionPattern(LX lx) { | |
168 | super(lx); | |
169 | projection = new LXProjection(model); | |
170 | addModulator(angle).trigger(); | |
171 | addModulator(yPos).trigger(); | |
172 | } | |
173 | ||
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 | |
178 | projection.reset() | |
179 | ||
180 | // Translate so the center of the car is the origin, offset by yPos | |
181 | .translateCenter(0, yPos.getValuef(), 0) | |
182 | ||
183 | // Rotate around the origin (now the center of the car) about an X-vector | |
184 | .rotate(angle.getValuef(), 1, 0, 0) | |
185 | ||
186 | // Scale up the Y axis (objects will look smaller in that access) | |
187 | .scale(1, 1.5, 1); | |
188 | ||
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, | |
196 | 100, | |
197 | constrain(140 - 40*d, 0, 100) | |
198 | ); | |
199 | } | |
200 | } | |
201 | } | |
202 | ||
203 | class TestCubePattern extends TestPattern { | |
204 | ||
205 | private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60); | |
206 | ||
207 | TestCubePattern(LX lx) { | |
208 | super(lx); | |
209 | addModulator(index).start(); | |
210 | } | |
211 | ||
212 | public void run(double deltaMs) { | |
213 | for (Cube c : model.cubes) { | |
214 | int i = 0; | |
215 | for (LXPoint p : c.points) { | |
216 | colors[p.index] = lx.hsb( | |
217 | lx.getBaseHuef(), | |
218 | 100, | |
219 | max(0, 100 - 80.*abs(i - index.getValuef())) | |
220 | ); | |
221 | ++i; | |
222 | } | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | class MappingTool extends TestPattern { | |
228 | ||
229 | private int cubeIndex = 0; | |
230 | private int stripIndex = 0; | |
231 | ||
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; | |
236 | ||
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; | |
241 | ||
242 | public boolean channelModeRed = true; | |
243 | public boolean channelModeGreen = false; | |
244 | public boolean channelModeBlue = false; | |
245 | ||
246 | MappingTool(LX lx) { | |
247 | super(lx); | |
248 | } | |
249 | ||
250 | private int indexOfCubeInChannel(Cube c) { | |
251 | // TODO(mcslee): port to grizzly | |
252 | return -1; | |
253 | } | |
254 | ||
255 | private void printInfo() { | |
256 | println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1)); | |
257 | } | |
258 | ||
259 | public void cube(int delta) { | |
260 | int len = model.cubes.size(); | |
261 | cubeIndex = (len + cubeIndex + delta) % len; | |
262 | printInfo(); | |
263 | } | |
264 | ||
265 | public void strip(int delta) { | |
266 | int len = Cube.STRIPS_PER_CUBE; | |
267 | stripIndex = (len + stripIndex + delta) % len; | |
268 | printInfo(); | |
269 | } | |
270 | ||
271 | public void run(double deltaMs) { | |
272 | color off = #000000; | |
273 | color c = off; | |
274 | color r = #FF0000; | |
275 | color g = #00FF00; | |
276 | color b = #0000FF; | |
277 | if (channelModeRed) c |= r; | |
278 | if (channelModeGreen) c |= g; | |
279 | if (channelModeBlue) c |= b; | |
280 | ||
281 | int ci = 0; | |
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; | |
289 | } | |
290 | if (cubeOn) { | |
291 | if (mappingMode == MAPPING_MODE_CHANNEL) { | |
292 | color cc = off; | |
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; | |
299 | } | |
300 | setColor(cube, cc); | |
301 | } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) { | |
302 | int si = 0; | |
303 | color sc = off; | |
304 | for (Strip strip : cube.strips) { | |
305 | int faceI = si / Face.STRIPS_PER_FACE; | |
306 | switch (faceI) { | |
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; | |
311 | } | |
312 | if (si % Face.STRIPS_PER_FACE == 2) { | |
313 | sc = r|g; | |
314 | } | |
315 | setColor(strip, sc); | |
316 | ++si; | |
317 | } | |
318 | } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) { | |
319 | setColor(cube, off); | |
320 | setColor(cube.strips.get(stripIndex), c); | |
321 | } else { | |
322 | setColor(cube, c); | |
323 | } | |
324 | } else { | |
325 | setColor(cube, off); | |
326 | } | |
327 | ++ci; | |
328 | } | |
329 | } | |
330 | ||
331 | public void setCube(int index) { | |
332 | cubeIndex = index % model.cubes.size(); | |
333 | } | |
334 | ||
335 | public void incCube() { | |
336 | cubeIndex = (cubeIndex + 1) % model.cubes.size(); | |
337 | } | |
338 | ||
339 | public void decCube() { | |
340 | --cubeIndex; | |
341 | if (cubeIndex < 0) { | |
342 | cubeIndex += model.cubes.size(); | |
343 | } | |
344 | } | |
345 | ||
346 | public void setStrip(int index) { | |
347 | stripIndex = index % Cube.STRIPS_PER_CUBE; | |
348 | } | |
349 | ||
350 | public void incStrip() { | |
351 | stripIndex = (stripIndex + 1) % Cube.STRIPS_PER_CUBE; | |
352 | } | |
353 | ||
354 | public void decStrip() { | |
355 | stripIndex = (stripIndex + Cube.STRIPS_PER_CUBE - 1) % Cube.STRIPS_PER_CUBE; | |
356 | } | |
357 | ||
358 | public void keyPressed(UIMapping uiMapping) { | |
359 | switch (keyCode) { | |
360 | case UP: incCube(); break; | |
361 | case DOWN: decCube(); break; | |
362 | case LEFT: decStrip(); break; | |
363 | case RIGHT: incStrip(); break; | |
364 | } | |
365 | switch (key) { | |
366 | case 'r': channelModeRed = !channelModeRed; break; | |
367 | case 'g': channelModeGreen = !channelModeGreen; break; | |
368 | case 'b': channelModeBlue = !channelModeBlue; break; | |
369 | } | |
370 | uiMapping.setCubeID(cubeIndex+1); | |
371 | uiMapping.setStripID(stripIndex+1); | |
372 | uiMapping.redraw(); | |
373 | } | |
374 | ||
375 | } |