Minor UI cleanups, make spacing and border colors consistent
[SugarCubes.git] / MarkSlee.pde
CommitLineData
49815cc0
MS
1class SpaceTime extends SCPattern {
2
3e8e60d8 3 SinLFO pos = new SinLFO(0, 1, 3000);
49815cc0
MS
4 SinLFO rate = new SinLFO(1000, 9000, 13000);
5 SinLFO falloff = new SinLFO(10, 70, 5000);
3f8be614
MS
6 float angle = 0;
7
8 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
9 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
49815cc0 10
3e8e60d8 11
49815cc0
MS
12 public SpaceTime(GLucose glucose) {
13 super(glucose);
3e8e60d8 14
49815cc0
MS
15 addModulator(pos).trigger();
16 addModulator(rate).trigger();
17 addModulator(falloff).trigger();
18 pos.modulateDurationBy(rate);
3f8be614
MS
19 addParameter(rateParameter);
20 addParameter(sizeParameter);
49815cc0 21 }
3f8be614
MS
22
23 public void onParameterChanged(LXParameter parameter) {
24 if (parameter == rateParameter) {
25 rate.stop().setValue(9000 - 8000*parameter.getValuef());
26 } else if (parameter == sizeParameter) {
27 falloff.stop().setValue(70 - 60*parameter.getValuef());
49815cc0
MS
28 }
29 }
30
31 void run(int deltaMs) {
3f8be614 32 angle += deltaMs * 0.0007;
87f6fa39
MS
33 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
34 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
49815cc0
MS
35
36 float pVal = pos.getValuef();
37 float fVal = falloff.getValuef();
38
39 int s = 0;
cfc57fca 40 for (Strip strip : model.strips) {
49815cc0
MS
41 int i = 0;
42 for (Point p : strip.points) {
43 colors[p.index] = color(
3e8e60d8
MS
44 (lx.getBaseHuef() + 360 - p.fx*.2 + p.fy * .3) % 360,
45 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
46 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
47 );
49815cc0
MS
48 ++i;
49 }
3f8be614 50 ++s;
49815cc0
MS
51 }
52 }
53}
54
55class Swarm extends SCPattern {
56
3e8e60d8 57 SawLFO offset = new SawLFO(0, 1, 1000);
49815cc0
MS
58 SinLFO rate = new SinLFO(350, 1200, 63000);
59 SinLFO falloff = new SinLFO(15, 50, 17000);
c39f7a04
MS
60 SinLFO fX = new SinLFO(0, model.xMax, 19000);
61 SinLFO fY = new SinLFO(0, model.yMax, 11000);
62 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
49815cc0
MS
63
64 public Swarm(GLucose glucose) {
65 super(glucose);
3e8e60d8 66
49815cc0
MS
67 addModulator(offset).trigger();
68 addModulator(rate).trigger();
69 addModulator(falloff).trigger();
2b6688e8 70 addModulator(fX).trigger();
49815cc0 71 addModulator(fY).trigger();
2b6688e8 72 addModulator(hOffX).trigger();
49815cc0
MS
73 offset.modulateDurationBy(rate);
74 }
75
76 float modDist(float v1, float v2, float mod) {
77 v1 = v1 % mod;
78 v2 = v2 % mod;
79 if (v2 > v1) {
80 return min(v2-v1, v1+mod-v2);
81 }
82 else {
83 return min(v1-v2, v2+mod-v1);
84 }
85 }
86
87 void run(int deltaMs) {
88 float s = 0;
cfc57fca 89 for (Strip strip : model.strips ) {
49815cc0
MS
90 int i = 0;
91 for (Point p : strip.points) {
2b6688e8 92 float fV = max(-1, 1 - dist(p.fx/2., p.fy, fX.getValuef()/2., fY.getValuef()) / 64.);
49815cc0 93 colors[p.index] = color(
2b6688e8 94 (lx.getBaseHuef() + 0.3 * abs(p.fx - hOffX.getValuef())) % 360,
49815cc0 95 constrain(80 + 40 * fV, 0, 100),
3e8e60d8 96 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, (int) (offset.getValuef() * strip.metrics.numPoints), strip.metrics.numPoints), 0, 100)
49815cc0
MS
97 );
98 ++i;
99 }
100 ++s;
101 }
102 }
103}
104
105class SwipeTransition extends SCTransition {
3f8be614
MS
106
107 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
108
49815cc0
MS
109 SwipeTransition(GLucose glucose) {
110 super(glucose);
111 setDuration(5000);
3f8be614 112 addParameter(bleed);
49815cc0
MS
113 }
114
115 void computeBlend(int[] c1, int[] c2, double progress) {
3f8be614 116 float bleedf = 10 + bleed.getValuef() * 200.;
c39f7a04 117 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
87f6fa39 118 for (Point p : model.points) {
2b6688e8 119 float d = (p.fx - xPos) / bleedf;
49815cc0
MS
120 if (d < 0) {
121 colors[p.index] = c2[p.index];
2b6688e8 122 } else if (d > 1) {
49815cc0 123 colors[p.index] = c1[p.index];
2b6688e8 124 } else {
49815cc0
MS
125 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
126 }
127 }
128 }
129}
130
ed149627
MS
131class MaskTransition extends SCTransition {
132
133 MaskTransition(GLucose glucose) {
134 super(glucose);
135 }
136
137 void computeBlend(int[] c1, int[] c2, double progress) {
138 if (progress < 0.5) {
139 for (int i = 0; i < c1.length; ++i) {
140 colors[i] = lerpColor(
141 c1[i],
142 blendColor(c1[i], c2[i], MULTIPLY),
143 (float) (2.*progress),
144 RGB);
145 }
146 } else {
147 for (int i = 0; i < c1.length; ++i) {
148 colors[i] = lerpColor(
149 c2[i],
150 blendColor(c1[i], c2[i], MULTIPLY),
151 (float) (2.*(1. - progress)),
152 RGB);
153 }
154 }
155 }
156}
157
158
4c006f7b
MS
159class BassPod extends SCPattern {
160
161 private GraphicEQ eq = null;
162
163 public BassPod(GLucose glucose) {
164 super(glucose);
165 }
166
167 protected void onActive() {
168 if (eq == null) {
169 eq = new GraphicEQ(lx, 16);
170 eq.slope.setValue(0.6);
171 addParameter(eq.level);
172 addParameter(eq.range);
173 addParameter(eq.attack);
174 addParameter(eq.release);
175 addParameter(eq.slope);
176 }
177 }
178
179 public void run(int deltaMs) {
180 eq.run(deltaMs);
181
182 float bassLevel = eq.getAverageLevel(0, 5);
183
184 for (Point p : model.points) {
185 int avgIndex = (int) constrain(1 + abs(p.fx-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
186 float value = 0;
187 for (int i = avgIndex; i < avgIndex + 5; ++i) {
188 value += eq.getLevel(i);
189 }
190 value /= 5.;
191
192 float b = constrain(8 * (value*model.yMax - abs(p.fy-model.yMax/2.)), 0, 100);
193 colors[p.index] = color(
194 (lx.getBaseHuef() + abs(p.fy - model.cy) + abs(p.fx - model.cx)) % 360,
195 constrain(bassLevel*240 - .6*dist(p.fx, p.fy, model.cx, model.cy), 0, 100),
196 b
197 );
198 }
199 }
200}
201
202
49815cc0
MS
203class CubeEQ extends SCPattern {
204
4c006f7b 205 private GraphicEQ eq = null;
49815cc0 206
3f8be614 207 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
3f8be614 208 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
4c006f7b 209 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
49815cc0
MS
210
211 public CubeEQ(GLucose glucose) {
212 super(glucose);
49815cc0 213 }
3f8be614 214
49815cc0 215 protected void onActive() {
4c006f7b
MS
216 if (eq == null) {
217 eq = new GraphicEQ(lx, 16);
218 addParameter(eq.level);
219 addParameter(eq.range);
220 addParameter(eq.attack);
221 addParameter(eq.release);
222 addParameter(eq.slope);
223 addParameter(edge);
224 addParameter(clr);
225 addParameter(blockiness);
49815cc0
MS
226 }
227 }
228
229 public void run(int deltaMs) {
4c006f7b 230 eq.run(deltaMs);
3f8be614 231
4c006f7b 232 float edgeConst = 2 + 30*edge.getValuef();
49815cc0
MS
233 float clrConst = 1.1 + clr.getValuef();
234
87f6fa39 235 for (Point p : model.points) {
4c006f7b 236 float avgIndex = constrain(2 + p.fx / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
49815cc0 237 int avgFloor = (int) avgIndex;
3f8be614 238
4c006f7b
MS
239 float leftVal = eq.getLevel(avgFloor);
240 float rightVal = eq.getLevel(avgFloor+1);
241 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
242
243 float chunkyValue = (
244 eq.getLevel(avgFloor/4*4) +
245 eq.getLevel(avgFloor/4*4 + 1) +
246 eq.getLevel(avgFloor/4*4 + 2) +
247 eq.getLevel(avgFloor/4*4 + 3)
248 ) / 4.;
249
250 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
251
252 float b = constrain(edgeConst * (value*model.yMax - p.fy), 0, 100);
49815cc0 253 colors[p.index] = color(
4c006f7b
MS
254 (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360,
255 100,
256 b
257 );
3f8be614
MS
258 }
259 }
260}
261
262class BoomEffect extends SCEffect {
263
264 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
265 final BasicParameter speed = new BasicParameter("SPD", 0.5);
266 final BasicParameter bright = new BasicParameter("BRT", 1.0);
267 final BasicParameter sat = new BasicParameter("SAT", 0.2);
268 List<Layer> layers = new ArrayList<Layer>();
c39f7a04 269 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
3f8be614
MS
270
271 class Layer {
272 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
273
274 Layer() {
275 addModulator(boom);
276 trigger();
277 }
278
279 void trigger() {
280 float falloffv = falloffv();
2b6688e8 281 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
3f8be614
MS
282 boom.trigger();
283 }
284
285 void doApply(int[] colors) {
286 float brightv = 100 * bright.getValuef();
287 float falloffv = falloffv();
288 float satv = sat.getValuef() * 100;
289 float huev = lx.getBaseHuef();
87f6fa39 290 for (Point p : model.points) {
3f8be614
MS
291 colors[p.index] = blendColor(
292 colors[p.index],
c39f7a04 293 color(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.fx, 2*p.fy, 3*p.fz, model.xMax/2, model.yMax, model.zMax*1.5)), 0, 100)),
3f8be614
MS
294 ADD);
295 }
296 }
297 }
298
299 BoomEffect(GLucose glucose) {
300 super(glucose, true);
301 addParameter(falloff);
302 addParameter(speed);
303 addParameter(bright);
304 addParameter(sat);
305 }
306
307 public void onEnable() {
308 for (Layer l : layers) {
309 if (!l.boom.isRunning()) {
310 l.trigger();
311 return;
312 }
313 }
314 layers.add(new Layer());
315 }
316
317 private float falloffv() {
318 return 20 - 19 * falloff.getValuef();
319 }
320
321 public void onTrigger() {
322 onEnable();
323 }
324
325 public void doApply(int[] colors) {
326 for (Layer l : layers) {
327 if (l.boom.isRunning()) {
328 l.doApply(colors);
329 }
49815cc0
MS
330 }
331 }
332}
333
5d70e4d7
MS
334public class PianoKeyPattern extends SCPattern {
335
336 final LinearEnvelope[] cubeBrt;
337 final SinLFO base[];
338 final BasicParameter attack = new BasicParameter("ATK", 0.1);
339 final BasicParameter release = new BasicParameter("REL", 0.5);
340 final BasicParameter level = new BasicParameter("AMB", 0.6);
341
342 PianoKeyPattern(GLucose glucose) {
343 super(glucose);
344
345 for (MidiInputDevice input : RWMidi.getInputDevices()) {
346 input.createInput(this);
347 }
348
349 addParameter(attack);
350 addParameter(release);
351 addParameter(level);
87f6fa39 352 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
5d70e4d7
MS
353 for (int i = 0; i < cubeBrt.length; ++i) {
354 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
355 }
87f6fa39 356 base = new SinLFO[model.cubes.size() / 12];
5d70e4d7
MS
357 for (int i = 0; i < base.length; ++i) {
358 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
359 }
360 }
361
362 private float getAttackTime() {
363 return 15 + attack.getValuef()*attack.getValuef() * 2000;
364 }
365
366 private float getReleaseTime() {
367 return 15 + release.getValuef() * 3000;
368 }
369
370 private LinearEnvelope getEnvelope(int index) {
371 return cubeBrt[index % cubeBrt.length];
372 }
373
374 private SinLFO getBase(int index) {
375 return base[index % base.length];
376 }
377
378 public void noteOnReceived(Note note) {
379 LinearEnvelope env = getEnvelope(note.getPitch());
380 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
381 }
382
383 public void noteOffReceived(Note note) {
384 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
385 }
386
387 public void run(int deltaMs) {
388 int i = 0;
389 float huef = lx.getBaseHuef();
390 float levelf = level.getValuef();
87f6fa39 391 for (Cube c : model.cubes) {
5d70e4d7
MS
392 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
393 setColor(c, color(
e0cea600 394 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
5d70e4d7
MS
395 min(100, 120*v),
396 100*v
397 ));
398 }
399 }
400}
401
0106b29c
MS
402class CrossSections extends SCPattern {
403
c39f7a04
MS
404 final SinLFO x = new SinLFO(0, model.xMax, 5000);
405 final SinLFO y = new SinLFO(0, model.yMax, 6000);
406 final SinLFO z = new SinLFO(0, model.zMax, 7000);
0106b29c
MS
407
408 final BasicParameter xw = new BasicParameter("XWID", 0.3);
409 final BasicParameter yw = new BasicParameter("YWID", 0.3);
410 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
2b6688e8 411 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
0106b29c 412 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
2b6688e8
MS
413 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
414 final BasicParameter xl = new BasicParameter("XLEV", 1);
0106b29c 415 final BasicParameter yl = new BasicParameter("YLEV", 1);
2b6688e8 416 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
0106b29c
MS
417
418
419 CrossSections(GLucose glucose) {
420 super(glucose);
421 addModulator(x).trigger();
422 addModulator(y).trigger();
423 addModulator(z).trigger();
b12bca62
MS
424 addParams();
425 }
426
427 protected void addParams() {
0106b29c
MS
428 addParameter(xr);
429 addParameter(yr);
430 addParameter(zr);
2b6688e8 431 addParameter(xw);
0106b29c
MS
432 addParameter(xl);
433 addParameter(yl);
434 addParameter(zl);
2b6688e8
MS
435 addParameter(yw);
436 addParameter(zw);
0106b29c 437 }
3e8e60d8
MS
438
439 void onParameterChanged(LXParameter p) {
0106b29c 440 if (p == xr) {
2b6688e8 441 x.setDuration(10000 - 8800*p.getValuef());
0106b29c 442 } else if (p == yr) {
2b6688e8 443 y.setDuration(10000 - 9000*p.getValuef());
0106b29c
MS
444 } else if (p == zr) {
445 z.setDuration(10000 - 9000*p.getValuef());
446 }
0106b29c 447 }
b12bca62
MS
448
449 float xv, yv, zv;
450
451 protected void updateXYZVals() {
452 xv = x.getValuef();
453 yv = y.getValuef();
454 zv = z.getValuef();
455 }
0106b29c
MS
456
457 public void run(int deltaMs) {
f1c74267
MS
458 updateXYZVals();
459
0106b29c
MS
460 float xlv = 100*xl.getValuef();
461 float ylv = 100*yl.getValuef();
462 float zlv = 100*zl.getValuef();
463
464 float xwv = 100. / (10 + 40*xw.getValuef());
465 float ywv = 100. / (10 + 40*yw.getValuef());
466 float zwv = 100. / (10 + 40*zw.getValuef());
467
87f6fa39 468 for (Point p : model.points) {
0106b29c
MS
469 color c = 0;
470 c = blendColor(c, color(
2b6688e8 471 (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360,
c39f7a04 472 constrain(140 - 1.1*abs(p.fx - model.xMax/2.), 0, 100),
2b6688e8 473 max(0, xlv - xwv*abs(p.fx - xv))
0106b29c
MS
474 ), ADD);
475 c = blendColor(c, color(
2b6688e8 476 (lx.getBaseHuef() + 80 + p.fy/10) % 360,
c39f7a04 477 constrain(140 - 2.2*abs(p.fy - model.yMax/2.), 0, 100),
2b6688e8 478 max(0, ylv - ywv*abs(p.fy - yv))
0106b29c
MS
479 ), ADD);
480 c = blendColor(c, color(
2b6688e8 481 (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360,
c39f7a04 482 constrain(140 - 2.2*abs(p.fz - model.zMax/2.), 0, 100),
2b6688e8 483 max(0, zlv - zwv*abs(p.fz - zv))
0106b29c
MS
484 ), ADD);
485 colors[p.index] = c;
486 }
487 }
488}
489
490class Blinders extends SCPattern {
491
aa54c1ca 492 final SinLFO[] m;
0106b29c
MS
493 final TriangleLFO r;
494 final SinLFO s;
495 final TriangleLFO hs;
496
497 public Blinders(GLucose glucose) {
498 super(glucose);
aa54c1ca
MS
499 m = new SinLFO[12];
500 for (int i = 0; i < m.length; ++i) {
501 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
502 }
503 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
504 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
0106b29c 505 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
aa54c1ca 506 s.modulateDurationBy(r);
0106b29c
MS
507 }
508
509 public void run(int deltaMs) {
510 float hv = lx.getBaseHuef();
aa54c1ca 511 int si = 0;
87f6fa39 512 for (Strip strip : model.strips) {
0106b29c 513 int i = 0;
aa54c1ca 514 float mv = m[si % m.length].getValuef();
0106b29c
MS
515 for (Point p : strip.points) {
516 colors[p.index] = color(
2b6688e8
MS
517 (hv + p.fz + p.fy*hs.getValuef()) % 360,
518 min(100, abs(p.fx - s.getValuef())/2.),
254fbb68 519 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
0106b29c
MS
520 );
521 ++i;
522 }
aa54c1ca 523 ++si;
0106b29c
MS
524 }
525 }
526}
527
87f6fa39
MS
528class Psychedelia extends SCPattern {
529
530 final int NUM = 3;
531 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
532 SinLFO s = new SinLFO(-20, 147, 11000);
533 TriangleLFO h = new TriangleLFO(0, 240, 19000);
534 SinLFO c = new SinLFO(-.2, .8, 31000);
535
536 Psychedelia(GLucose glucose) {
537 super(glucose);
538 addModulator(m).trigger();
539 addModulator(s).trigger();
540 addModulator(h).trigger();
541 addModulator(c).trigger();
542 }
0106b29c 543
87f6fa39
MS
544 void run(int deltaMs) {
545 float huev = h.getValuef();
546 float cv = c.getValuef();
547 float sv = s.getValuef();
548 float mv = m.getValuef();
549 int i = 0;
550 for (Strip strip : model.strips) {
551 for (Point p : strip.points) {
552 colors[p.index] = color(
553 (huev + i*constrain(cv, 0, 2) + p.fz/2. + p.fx/4.) % 360,
554 min(100, abs(p.fy-sv)),
555 max(0, 100 - 50*abs((i%NUM) - mv))
556 );
557 }
558 ++i;
559 }
560 }
561}
5129affb
MS
562
563class AskewPlanes extends SCPattern {
564
565 class Plane {
566 private final SinLFO a;
567 private final SinLFO b;
568 private final SinLFO c;
775d3394
MS
569 float av = 1;
570 float bv = 1;
571 float cv = 1;
572 float denom = 0.1;
5129affb
MS
573
574 Plane(int i) {
575 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
576 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
577 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
578 }
579
580 void run(int deltaMs) {
581 av = a.getValuef();
582 bv = b.getValuef();
583 cv = c.getValuef();
584 denom = sqrt(av*av + bv*bv);
585 }
586 }
587
588 final Plane[] planes;
589 final int NUM_PLANES = 3;
590
591 AskewPlanes(GLucose glucose) {
592 super(glucose);
593 planes = new Plane[NUM_PLANES];
594 for (int i = 0; i < planes.length; ++i) {
595 planes[i] = new Plane(i);
596 }
597 }
5129affb
MS
598
599 public void run(int deltaMs) {
600 float huev = lx.getBaseHuef();
775d3394
MS
601
602 // This is super fucking bizarre. But if this is a for loop, the framerate
603 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
604 // Doesn't make ANY sense... there must be some weird side effect going on
605 // with the Processing internals perhaps?
606// for (Plane plane : planes) {
607// plane.run(deltaMs);
608// }
609 planes[0].run(deltaMs);
610 planes[1].run(deltaMs);
611 planes[2].run(deltaMs);
612
5129affb 613 for (Point p : model.points) {
775d3394
MS
614 float d = MAX_FLOAT;
615 for (Plane plane : planes) {
616 if (plane.denom != 0) {
617 d = min(d, abs(plane.av*(p.fx-model.cx) + plane.bv*(p.fy-model.cy) + plane.cv) / plane.denom);
618 }
619 }
620 colors[p.index] = color(
621 (huev + abs(p.fx-model.cx)*.3 + p.fy*.8) % 360,
622 max(0, 100 - .8*abs(p.fx - model.cx)),
623 constrain(140 - 10.*d, 0, 100)
624 );
5129affb
MS
625 }
626 }
627}
628
629class ShiftingPlane extends SCPattern {
630
631 final SinLFO a = new SinLFO(-.2, .2, 5300);
632 final SinLFO b = new SinLFO(1, -1, 13300);
633 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
634 final SinLFO d = new SinLFO(-10, 10, 9500);
635
636 ShiftingPlane(GLucose glucose) {
637 super(glucose);
638 addModulator(a).trigger();
639 addModulator(b).trigger();
640 addModulator(c).trigger();
641 addModulator(d).trigger();
642 }
643
644 public void run(int deltaMs) {
645 float hv = lx.getBaseHuef();
646 float av = a.getValuef();
647 float bv = b.getValuef();
648 float cv = c.getValuef();
649 float dv = d.getValuef();
650 float denom = sqrt(av*av + bv*bv + cv*cv);
651 for (Point p : model.points) {
775d3394 652 float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom;
5129affb 653 colors[p.index] = color(
775d3394 654 (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360,
5129affb
MS
655 constrain(110 - d*6, 0, 100),
656 constrain(130 - 7*d, 0, 100)
657 );
658 }
659 }
660}
f3f5a876 661
4c006f7b
MS
662class Traktor extends SCPattern {
663
664 final int FRAME_WIDTH = 60;
665
666 final BasicParameter speed = new BasicParameter("SPD", 0.5);
667
668 private float[] bass = new float[FRAME_WIDTH];
669 private float[] treble = new float[FRAME_WIDTH];
670
671 private int index = 0;
672 private GraphicEQ eq = null;
673
674 public Traktor(GLucose glucose) {
675 super(glucose);
676 for (int i = 0; i < FRAME_WIDTH; ++i) {
677 bass[i] = 0;
678 treble[i] = 0;
679 }
680 addParameter(speed);
681 }
682
683 public void onActive() {
684 if (eq == null) {
685 eq = new GraphicEQ(lx, 16);
686 eq.slope.setValue(0.6);
687 eq.level.setValue(0.65);
688 eq.range.setValue(0.35);
689 eq.release.setValue(0.4);
690 addParameter(eq.level);
691 addParameter(eq.range);
692 addParameter(eq.attack);
693 addParameter(eq.release);
694 addParameter(eq.slope);
695 }
696 }
697
698 int counter = 0;
699
700 public void run(int deltaMs) {
701 eq.run(deltaMs);
702
703 int stepThresh = (int) (40 - 39*speed.getValuef());
704 counter += deltaMs;
705 if (counter < stepThresh) {
706 return;
707 }
708 counter = counter % stepThresh;
709
710 index = (index + 1) % FRAME_WIDTH;
711
712 float rawBass = eq.getAverageLevel(0, 4);
713 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
714
715 bass[index] = rawBass * rawBass * rawBass * rawBass;
716 treble[index] = rawTreble * rawTreble;
717
718 for (Point p : model.points) {
719 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
720 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
721
722 colors[p.index] = color(
723 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
724 100,
725 constrain(9 * (bass[pos]*model.cy - abs(p.fy - model.cy)), 0, 100)
726 );
727 colors[p.index] = blendColor(colors[p.index], color(
728 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
729 60,
730 constrain(5 * (treble[pos]*.6*model.cy - abs(p.fy - model.cy)), 0, 100)
731
732 ), ADD);
733 }
734 }
735}
6702151a
MS
736
737class ColorFuckerEffect extends SCEffect {
738
739 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
740 BasicParameter sat = new BasicParameter("SAT", 1);
741 BasicParameter bright = new BasicParameter("BRT", 1);
742
743 ColorFuckerEffect(GLucose glucose) {
744 super(glucose);
745 addParameter(hueShift);
746 addParameter(bright);
747 addParameter(sat);
748 }
749
750 public void doApply(int[] colors) {
d626bc9b
MS
751 if (!enabled) {
752 return;
753 }
6702151a
MS
754 float bMod = bright.getValuef();
755 float sMod = sat.getValuef();
756 float hMod = hueShift.getValuef();
757 if (bMod < 1 || sMod < 1 || hMod > 0) {
758 for (int i = 0; i < colors.length; ++i) {
759 colors[i] = color(
760 (hue(colors[i]) + hueShift.getValuef()*360.) % 360,
761 saturation(colors[i]) * sat.getValuef(),
762 brightness(colors[i]) * bright.getValuef()
763 );
764 }
765 }
766 }
767}