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