Commit | Line | Data |
---|---|---|
6c1a9e53 MS |
1 | abstract class TestPattern extends SCPattern { |
2 | public TestPattern(GLucose glucose) { | |
3 | super(glucose); | |
4 | setEligible(false); | |
5 | } | |
6 | } | |
7 | ||
254fbb68 | 8 | class TestStripPattern extends TestPattern { |
e105ef7c MS |
9 | |
10 | SinLFO d = new SinLFO(4, 40, 4000); | |
11 | ||
254fbb68 MS |
12 | public TestStripPattern(GLucose glucose) { |
13 | super(glucose); | |
e105ef7c | 14 | addModulator(d).trigger(); |
254fbb68 MS |
15 | } |
16 | ||
17 | public void run(int deltaMs) { | |
18 | for (Strip s : model.strips) { | |
19 | for (Point p : s.points) { | |
20 | colors[p.index] = color( | |
21 | lx.getBaseHuef(), | |
22 | 100, | |
e105ef7c | 23 | max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy)) |
254fbb68 MS |
24 | ); |
25 | } | |
26 | } | |
27 | } | |
28 | } | |
29 | ||
7ef61b89 MS |
30 | /** |
31 | * Simplest demonstration of using the rotating master hue. | |
32 | * All pixels are full-on the same color. | |
33 | */ | |
6c1a9e53 | 34 | class TestHuePattern extends TestPattern { |
49815cc0 MS |
35 | public TestHuePattern(GLucose glucose) { |
36 | super(glucose); | |
37 | } | |
7ef61b89 | 38 | |
49815cc0 | 39 | public void run(int deltaMs) { |
7ef61b89 MS |
40 | // Access the core master hue via this method call |
41 | float hv = lx.getBaseHuef(); | |
49815cc0 | 42 | for (int i = 0; i < colors.length; ++i) { |
7ef61b89 | 43 | colors[i] = color(hv, 100, 100); |
49815cc0 MS |
44 | } |
45 | } | |
46 | } | |
47 | ||
7ef61b89 MS |
48 | /** |
49 | * Test of a wave moving across the X axis. | |
50 | */ | |
6c1a9e53 | 51 | class TestXPattern extends TestPattern { |
7ef61b89 | 52 | private final SinLFO xPos = new SinLFO(0, model.xMax, 4000); |
49815cc0 MS |
53 | public TestXPattern(GLucose glucose) { |
54 | super(glucose); | |
55 | addModulator(xPos).trigger(); | |
56 | } | |
57 | public void run(int deltaMs) { | |
7ef61b89 | 58 | float hv = lx.getBaseHuef(); |
87f6fa39 | 59 | for (Point p : model.points) { |
7ef61b89 MS |
60 | // This is a common technique for modulating brightness. |
61 | // You can use abs() to determine the distance between two | |
62 | // values. The further away this point is from an exact | |
63 | // point, the more we decrease its brightness | |
64 | float bv = max(0, 100 - abs(p.fx - xPos.getValuef())); | |
65 | colors[p.index] = color(hv, 100, bv); | |
49815cc0 MS |
66 | } |
67 | } | |
68 | } | |
69 | ||
7ef61b89 MS |
70 | /** |
71 | * Test of a wave on the Y axis. | |
72 | */ | |
6c1a9e53 | 73 | class TestYPattern extends TestPattern { |
7ef61b89 | 74 | private final SinLFO yPos = new SinLFO(0, model.yMax, 4000); |
49815cc0 MS |
75 | public TestYPattern(GLucose glucose) { |
76 | super(glucose); | |
77 | addModulator(yPos).trigger(); | |
78 | } | |
79 | public void run(int deltaMs) { | |
7ef61b89 | 80 | float hv = lx.getBaseHuef(); |
87f6fa39 | 81 | for (Point p : model.points) { |
7ef61b89 MS |
82 | float bv = max(0, 100 - abs(p.fy - yPos.getValuef())); |
83 | colors[p.index] = color(hv, 100, bv); | |
49815cc0 MS |
84 | } |
85 | } | |
86 | } | |
87 | ||
7ef61b89 MS |
88 | /** |
89 | * Test of a wave on the Z axis. | |
90 | */ | |
6c1a9e53 | 91 | class TestZPattern extends TestPattern { |
7ef61b89 | 92 | private final SinLFO zPos = new SinLFO(0, model.zMax, 4000); |
49815cc0 MS |
93 | public TestZPattern(GLucose glucose) { |
94 | super(glucose); | |
95 | addModulator(zPos).trigger(); | |
96 | } | |
97 | public void run(int deltaMs) { | |
7ef61b89 | 98 | float hv = lx.getBaseHuef(); |
87f6fa39 | 99 | for (Point p : model.points) { |
7ef61b89 MS |
100 | float bv = max(0, 100 - abs(p.fz - zPos.getValuef())); |
101 | colors[p.index] = color(hv, 100, bv); | |
49815cc0 MS |
102 | } |
103 | } | |
104 | } | |
f3f5a876 | 105 | |
186bc4d3 MS |
106 | /** |
107 | * This shows how to iterate over towers, enumerated in the model. | |
108 | */ | |
6c1a9e53 | 109 | class TestTowerPattern extends TestPattern { |
186bc4d3 MS |
110 | private final SawLFO towerIndex = new SawLFO(0, model.towers.size(), 1000*model.towers.size()); |
111 | ||
112 | public TestTowerPattern(GLucose glucose) { | |
113 | super(glucose); | |
114 | addModulator(towerIndex).trigger(); | |
186bc4d3 MS |
115 | } |
116 | ||
117 | public void run(int deltaMs) { | |
186bc4d3 MS |
118 | int ti = 0; |
119 | for (Tower t : model.towers) { | |
120 | for (Point p : t.points) { | |
121 | colors[p.index] = color( | |
122 | lx.getBaseHuef(), | |
123 | 100, | |
92341dd9 | 124 | max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size())) |
186bc4d3 MS |
125 | ); |
126 | } | |
127 | ++ti; | |
128 | } | |
129 | } | |
130 | ||
131 | } | |
132 | ||
7ef61b89 MS |
133 | /** |
134 | * This is a demonstration of how to use the projection library. A projection | |
135 | * creates a mutation of the coordinates of all the points in the model, creating | |
136 | * virtual x,y,z coordinates. In effect, this is like virtually rotating the entire | |
137 | * art car. However, since in reality the car does not move, the result is that | |
138 | * it appears that the object we are drawing on the car is actually moving. | |
139 | * | |
140 | * Keep in mind that what we are creating a projection of is the view coordinates. | |
141 | * Depending on your intuition, some operations may feel backwards. For instance, | |
142 | * if you translate the view to the right, it will make it seem that the object | |
143 | * you are drawing has moved to the left. If you scale the view up 2x, objects | |
144 | * drawn with the same absolute values will seem to be half the size. | |
145 | * | |
146 | * If this feels counterintuitive at first, don't worry. Just remember that you | |
147 | * are moving the pixels, not the structure. We're dealing with a finite set | |
148 | * of sparse, non-uniformly spaced pixels. Mutating the structure would move | |
149 | * things to a space where there are no pixels in 99% of the cases. | |
150 | */ | |
6c1a9e53 | 151 | class TestProjectionPattern extends TestPattern { |
f3f5a876 | 152 | |
7ef61b89 MS |
153 | private final Projection projection; |
154 | private final SawLFO angle = new SawLFO(0, TWO_PI, 9000); | |
155 | private final SinLFO yPos = new SinLFO(-20, 40, 5000); | |
f3f5a876 | 156 | |
7ef61b89 | 157 | public TestProjectionPattern(GLucose glucose) { |
f3f5a876 MS |
158 | super(glucose); |
159 | projection = new Projection(model); | |
160 | addModulator(angle).trigger(); | |
161 | addModulator(yPos).trigger(); | |
162 | } | |
163 | ||
164 | public void run(int deltaMs) { | |
7ef61b89 MS |
165 | // For the same reasons described above, it may logically feel to you that |
166 | // some of these operations are in reverse order. Again, just keep in mind that | |
167 | // the car itself is what's moving, not the object | |
f3f5a876 | 168 | projection.reset(model) |
7ef61b89 MS |
169 | |
170 | // Translate so the center of the car is the origin, offset by yPos | |
e0cea600 | 171 | .translateCenter(model, 0, yPos.getValuef(), 0) |
7ef61b89 MS |
172 | |
173 | // Rotate around the origin (now the center of the car) about an X-vector | |
f3f5a876 | 174 | .rotate(angle.getValuef(), 1, 0, 0) |
7ef61b89 MS |
175 | |
176 | // Scale up the Y axis (objects will look smaller in that access) | |
f3f5a876 MS |
177 | .scale(1, 1.5, 1); |
178 | ||
7ef61b89 | 179 | float hv = lx.getBaseHuef(); |
f3f5a876 MS |
180 | for (Coord c : projection) { |
181 | float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin | |
182 | // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing | |
e105ef7c | 183 | d = max(0, abs(c.y) - 10 + .1*abs(c.z) + .02*abs(c.x)); // plane / spear thing |
f3f5a876 | 184 | colors[c.index] = color( |
7ef61b89 | 185 | (hv + .6*abs(c.x) + abs(c.z)) % 360, |
f3f5a876 | 186 | 100, |
e105ef7c | 187 | constrain(140 - 40*d, 0, 100) |
f3f5a876 MS |
188 | ); |
189 | } | |
190 | } | |
191 | } | |
bf551144 | 192 | |
6c1a9e53 | 193 | class TestCubePattern extends TestPattern { |
254d34c0 | 194 | |
cdb88d5d | 195 | private SawLFO index = new SawLFO(0, Cube.POINTS_PER_CUBE, Cube.POINTS_PER_CUBE*60); |
254d34c0 MS |
196 | |
197 | TestCubePattern(GLucose glucose) { | |
198 | super(glucose); | |
199 | addModulator(index).start(); | |
200 | } | |
201 | ||
202 | public void run(int deltaMs) { | |
203 | for (Cube c : model.cubes) { | |
204 | int i = 0; | |
205 | for (Point p : c.points) { | |
206 | colors[p.index] = color( | |
207 | lx.getBaseHuef(), | |
208 | 100, | |
209 | max(0, 100 - 80.*abs(i - index.getValuef())) | |
210 | ); | |
211 | ++i; | |
212 | } | |
213 | } | |
214 | } | |
215 | } | |
216 | ||
6c1a9e53 | 217 | class MappingTool extends TestPattern { |
bf551144 MS |
218 | |
219 | private int cubeIndex = 0; | |
220 | private int stripIndex = 0; | |
2bae07c9 | 221 | private int channelIndex = 0; |
bf551144 | 222 | |
2bae07c9 MS |
223 | public final int MAPPING_MODE_ALL = 0; |
224 | public final int MAPPING_MODE_CHANNEL = 1; | |
225 | public final int MAPPING_MODE_SINGLE_CUBE = 2; | |
226 | public int mappingMode = MAPPING_MODE_ALL; | |
bf551144 MS |
227 | |
228 | public final int CUBE_MODE_ALL = 0; | |
229 | public final int CUBE_MODE_SINGLE_STRIP = 1; | |
230 | public final int CUBE_MODE_STRIP_PATTERN = 2; | |
231 | public int cubeMode = CUBE_MODE_ALL; | |
232 | ||
233 | public boolean channelModeRed = true; | |
234 | public boolean channelModeGreen = false; | |
235 | public boolean channelModeBlue = false; | |
236 | ||
45f43cc2 | 237 | private final int numChannels; |
2bae07c9 | 238 | |
45f43cc2 | 239 | private final PandaMapping[] pandaMappings; |
84086fa3 MS |
240 | private PandaMapping activePanda; |
241 | private ChannelMapping activeChannel; | |
2bae07c9 | 242 | |
45f43cc2 | 243 | MappingTool(GLucose glucose, PandaMapping[] pandaMappings) { |
bf551144 | 244 | super(glucose); |
45f43cc2 | 245 | this.pandaMappings = pandaMappings; |
1685dc84 | 246 | numChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD; |
2bae07c9 MS |
247 | setChannel(); |
248 | } | |
249 | ||
250 | private void setChannel() { | |
84086fa3 MS |
251 | activePanda = pandaMappings[channelIndex / PandaMapping.CHANNELS_PER_BOARD]; |
252 | activeChannel = activePanda.channelList[channelIndex % PandaMapping.CHANNELS_PER_BOARD]; | |
2bae07c9 MS |
253 | } |
254 | ||
84086fa3 MS |
255 | private int indexOfCubeInChannel(Cube c) { |
256 | if (activeChannel.mode == ChannelMapping.MODE_CUBES) { | |
257 | int i = 1; | |
258 | for (int index : activeChannel.objectIndices) { | |
9f823de4 | 259 | if ((index >= 0) && (c == model.getCubeByRawIndex(index))) { |
84086fa3 MS |
260 | return i; |
261 | } | |
262 | ++i; | |
2bae07c9 | 263 | } |
2bae07c9 MS |
264 | } |
265 | return 0; | |
bf551144 MS |
266 | } |
267 | ||
268 | private void printInfo() { | |
269 | println("Cube:" + cubeIndex + " Strip:" + (stripIndex+1)); | |
270 | } | |
271 | ||
272 | public void cube(int delta) { | |
273 | int len = model.cubes.size(); | |
274 | cubeIndex = (len + cubeIndex + delta) % len; | |
275 | printInfo(); | |
276 | } | |
277 | ||
278 | public void strip(int delta) { | |
45f43cc2 | 279 | int len = Cube.STRIPS_PER_CUBE; |
bf551144 MS |
280 | stripIndex = (len + stripIndex + delta) % len; |
281 | printInfo(); | |
282 | } | |
283 | ||
284 | public void run(int deltaMs) { | |
285 | color off = color(0, 0, 0); | |
286 | color c = off; | |
287 | color r = #FF0000; | |
288 | color g = #00FF00; | |
289 | color b = #0000FF; | |
290 | if (channelModeRed) c |= r; | |
291 | if (channelModeGreen) c |= g; | |
292 | if (channelModeBlue) c |= b; | |
293 | ||
294 | int ci = 0; | |
295 | for (Cube cube : model.cubes) { | |
2bae07c9 | 296 | boolean cubeOn = false; |
84086fa3 | 297 | int indexOfCubeInChannel = indexOfCubeInChannel(cube); |
2bae07c9 MS |
298 | switch (mappingMode) { |
299 | case MAPPING_MODE_ALL: cubeOn = true; break; | |
300 | case MAPPING_MODE_SINGLE_CUBE: cubeOn = (cubeIndex == ci); break; | |
301 | case MAPPING_MODE_CHANNEL: cubeOn = (channelIndex > 0); break; | |
302 | } | |
303 | if (cubeOn) { | |
304 | if (mappingMode == MAPPING_MODE_CHANNEL) { | |
305 | color cc = off; | |
84086fa3 | 306 | switch (indexOfCubeInChannel) { |
2bae07c9 MS |
307 | case 1: cc = r; break; |
308 | case 2: cc = r|g; break; | |
309 | case 3: cc = g; break; | |
310 | case 4: cc = b; break; | |
311 | case 5: cc = r|b; break; | |
312 | } | |
313 | setColor(cube, cc); | |
314 | } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) { | |
bf551144 MS |
315 | int si = 0; |
316 | color sc = off; | |
317 | for (Strip strip : cube.strips) { | |
a797d019 MS |
318 | int faceI = si / Face.STRIPS_PER_FACE; |
319 | switch (faceI) { | |
bf551144 MS |
320 | case 0: sc = r; break; |
321 | case 1: sc = g; break; | |
322 | case 2: sc = b; break; | |
323 | case 3: sc = r|g|b; break; | |
324 | } | |
a797d019 | 325 | if (si % Face.STRIPS_PER_FACE == 2) { |
bf551144 MS |
326 | sc = r|g; |
327 | } | |
328 | setColor(strip, sc); | |
329 | ++si; | |
330 | } | |
331 | } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) { | |
332 | setColor(cube, off); | |
333 | setColor(cube.strips.get(stripIndex), c); | |
334 | } else { | |
335 | setColor(cube, c); | |
336 | } | |
337 | } else { | |
338 | setColor(cube, off); | |
339 | } | |
340 | ++ci; | |
341 | } | |
342 | ||
343 | } | |
344 | ||
345 | public void incCube() { | |
346 | cubeIndex = (cubeIndex + 1) % model.cubes.size(); | |
347 | } | |
348 | ||
349 | public void decCube() { | |
350 | --cubeIndex; | |
351 | if (cubeIndex < 0) { | |
352 | cubeIndex += model.cubes.size(); | |
353 | } | |
354 | } | |
2bae07c9 MS |
355 | |
356 | public void incChannel() { | |
45f43cc2 | 357 | channelIndex = (channelIndex + 1) % numChannels; |
2bae07c9 MS |
358 | setChannel(); |
359 | } | |
360 | ||
361 | public void decChannel() { | |
9f823de4 | 362 | channelIndex = (channelIndex + numChannels - 1) % numChannels; |
2bae07c9 MS |
363 | setChannel(); |
364 | } | |
bf551144 MS |
365 | |
366 | public void incStrip() { | |
92c06c97 | 367 | stripIndex = (stripIndex + 1) % Cube.STRIPS_PER_CUBE; |
bf551144 MS |
368 | } |
369 | ||
370 | public void decStrip() { | |
9f823de4 | 371 | stripIndex = (stripIndex + Cube.STRIPS_PER_CUBE - 1) % Cube.STRIPS_PER_CUBE; |
bf551144 MS |
372 | } |
373 | ||
374 | public void keyPressed() { | |
375 | switch (keyCode) { | |
2bae07c9 MS |
376 | case UP: if (mappingMode == MAPPING_MODE_CHANNEL) incChannel(); else incCube(); break; |
377 | case DOWN: if (mappingMode == MAPPING_MODE_CHANNEL) decChannel(); else decCube(); break; | |
bf551144 MS |
378 | case LEFT: decStrip(); break; |
379 | case RIGHT: incStrip(); break; | |
380 | } | |
381 | switch (key) { | |
382 | case 'r': channelModeRed = !channelModeRed; break; | |
383 | case 'g': channelModeGreen = !channelModeGreen; break; | |
384 | case 'b': channelModeBlue = !channelModeBlue; break; | |
385 | } | |
386 | } | |
387 | } |