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