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