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