1 class SpaceTime extends SCPattern {
3 SinLFO pos = new SinLFO(0, 1, 3000);
4 SinLFO rate = new SinLFO(1000, 9000, 13000);
5 SinLFO falloff = new SinLFO(10, 70, 5000);
8 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
9 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
12 public SpaceTime(GLucose glucose) {
15 addModulator(pos).trigger();
16 addModulator(rate).trigger();
17 addModulator(falloff).trigger();
18 pos.modulateDurationBy(rate);
19 addParameter(rateParameter);
20 addParameter(sizeParameter);
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());
31 void run(double deltaMs) {
32 angle += deltaMs * 0.0007;
33 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
34 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
36 float pVal = pos.getValuef();
37 float fVal = falloff.getValuef();
40 for (Strip strip : model.strips) {
42 for (Point p : strip.points) {
43 colors[p.index] = color(
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)))
55 class Swarm extends SCPattern {
57 SawLFO offset = new SawLFO(0, 1, 1000);
58 SinLFO rate = new SinLFO(350, 1200, 63000);
59 SinLFO falloff = new SinLFO(15, 50, 17000);
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);
64 public Swarm(GLucose glucose) {
67 addModulator(offset).trigger();
68 addModulator(rate).trigger();
69 addModulator(falloff).trigger();
70 addModulator(fX).trigger();
71 addModulator(fY).trigger();
72 addModulator(hOffX).trigger();
73 offset.modulateDurationBy(rate);
76 float modDist(float v1, float v2, float mod) {
80 return min(v2-v1, v1+mod-v2);
83 return min(v1-v2, v2+mod-v1);
87 void run(double deltaMs) {
89 for (Strip strip : model.strips ) {
91 for (Point p : strip.points) {
92 float fV = max(-1, 1 - dist(p.fx/2., p.fy, fX.getValuef()/2., fY.getValuef()) / 64.);
93 colors[p.index] = color(
94 (lx.getBaseHuef() + 0.3 * abs(p.fx - hOffX.getValuef())) % 360,
95 constrain(80 + 40 * fV, 0, 100),
96 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
105 class SwipeTransition extends SCTransition {
107 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
109 SwipeTransition(GLucose glucose) {
115 void computeBlend(int[] c1, int[] c2, double progress) {
116 float bleedf = 10 + bleed.getValuef() * 200.;
117 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
118 for (Point p : model.points) {
119 float d = (p.fx - xPos) / bleedf;
121 colors[p.index] = c2[p.index];
123 colors[p.index] = c1[p.index];
125 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
131 abstract class BlendTransition extends SCTransition {
135 BlendTransition(GLucose glucose, int blendType) {
137 this.blendType = blendType;
140 void computeBlend(int[] c1, int[] c2, double progress) {
141 if (progress < 0.5) {
142 for (int i = 0; i < c1.length; ++i) {
143 colors[i] = lerpColor(
145 blendColor(c1[i], c2[i], blendType),
146 (float) (2.*progress),
150 for (int i = 0; i < c1.length; ++i) {
151 colors[i] = lerpColor(
153 blendColor(c1[i], c2[i], blendType),
154 (float) (2.*(1. - progress)),
161 class MultiplyTransition extends BlendTransition {
162 MultiplyTransition(GLucose glucose) {
163 super(glucose, MULTIPLY);
167 class ScreenTransition extends BlendTransition {
168 ScreenTransition(GLucose glucose) {
169 super(glucose, SCREEN);
173 class BurnTransition extends BlendTransition {
174 BurnTransition(GLucose glucose) {
175 super(glucose, BURN);
179 class DodgeTransition extends BlendTransition {
180 DodgeTransition(GLucose glucose) {
181 super(glucose, DODGE);
185 class OverlayTransition extends BlendTransition {
186 OverlayTransition(GLucose glucose) {
187 super(glucose, OVERLAY);
191 class AddTransition extends BlendTransition {
192 AddTransition(GLucose glucose) {
197 class SubtractTransition extends BlendTransition {
198 SubtractTransition(GLucose glucose) {
199 super(glucose, SUBTRACT);
203 class SoftLightTransition extends BlendTransition {
204 SoftLightTransition(GLucose glucose) {
205 super(glucose, SOFT_LIGHT);
209 class BassPod extends SCPattern {
211 private GraphicEQ eq = null;
213 public BassPod(GLucose glucose) {
217 protected void onActive() {
219 eq = new GraphicEQ(lx, 16);
220 eq.slope.setValue(0.6);
221 addParameter(eq.level);
222 addParameter(eq.range);
223 addParameter(eq.attack);
224 addParameter(eq.release);
225 addParameter(eq.slope);
229 public void run(double deltaMs) {
232 float bassLevel = eq.getAverageLevel(0, 5);
234 for (Point p : model.points) {
235 int avgIndex = (int) constrain(1 + abs(p.fx-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
237 for (int i = avgIndex; i < avgIndex + 5; ++i) {
238 value += eq.getLevel(i);
242 float b = constrain(8 * (value*model.yMax - abs(p.fy-model.yMax/2.)), 0, 100);
243 colors[p.index] = color(
244 (lx.getBaseHuef() + abs(p.fy - model.cy) + abs(p.fx - model.cx)) % 360,
245 constrain(bassLevel*240 - .6*dist(p.fx, p.fy, model.cx, model.cy), 0, 100),
253 class CubeEQ extends SCPattern {
255 private GraphicEQ eq = null;
257 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
258 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
259 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
261 public CubeEQ(GLucose glucose) {
265 protected void onActive() {
267 eq = new GraphicEQ(lx, 16);
268 addParameter(eq.level);
269 addParameter(eq.range);
270 addParameter(eq.attack);
271 addParameter(eq.release);
272 addParameter(eq.slope);
275 addParameter(blockiness);
279 public void run(double deltaMs) {
282 float edgeConst = 2 + 30*edge.getValuef();
283 float clrConst = 1.1 + clr.getValuef();
285 for (Point p : model.points) {
286 float avgIndex = constrain(2 + p.fx / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
287 int avgFloor = (int) avgIndex;
289 float leftVal = eq.getLevel(avgFloor);
290 float rightVal = eq.getLevel(avgFloor+1);
291 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
293 float chunkyValue = (
294 eq.getLevel(avgFloor/4*4) +
295 eq.getLevel(avgFloor/4*4 + 1) +
296 eq.getLevel(avgFloor/4*4 + 2) +
297 eq.getLevel(avgFloor/4*4 + 3)
300 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
302 float b = constrain(edgeConst * (value*model.yMax - p.fy), 0, 100);
303 colors[p.index] = color(
304 (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360,
312 class BoomEffect extends SCEffect {
314 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
315 final BasicParameter speed = new BasicParameter("SPD", 0.5);
316 final BasicParameter bright = new BasicParameter("BRT", 1.0);
317 final BasicParameter sat = new BasicParameter("SAT", 0.2);
318 List<Layer> layers = new ArrayList<Layer>();
319 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
322 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
330 float falloffv = falloffv();
331 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
335 void doApply(int[] colors) {
336 float brightv = 100 * bright.getValuef();
337 float falloffv = falloffv();
338 float satv = sat.getValuef() * 100;
339 float huev = lx.getBaseHuef();
340 for (Point p : model.points) {
341 colors[p.index] = blendColor(
343 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)),
349 BoomEffect(GLucose glucose) {
350 super(glucose, true);
351 addParameter(falloff);
353 addParameter(bright);
357 public void onEnable() {
358 for (Layer l : layers) {
359 if (!l.boom.isRunning()) {
364 layers.add(new Layer());
367 private float falloffv() {
368 return 20 - 19 * falloff.getValuef();
371 public void onTrigger() {
375 public void doApply(int[] colors) {
376 for (Layer l : layers) {
377 if (l.boom.isRunning()) {
384 public class PianoKeyPattern extends SCPattern {
386 final LinearEnvelope[] cubeBrt;
388 final BasicParameter attack = new BasicParameter("ATK", 0.1);
389 final BasicParameter release = new BasicParameter("REL", 0.5);
390 final BasicParameter level = new BasicParameter("AMB", 0.6);
392 PianoKeyPattern(GLucose glucose) {
395 addParameter(attack);
396 addParameter(release);
398 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
399 for (int i = 0; i < cubeBrt.length; ++i) {
400 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
402 base = new SinLFO[model.cubes.size() / 12];
403 for (int i = 0; i < base.length; ++i) {
404 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
408 private float getAttackTime() {
409 return 15 + attack.getValuef()*attack.getValuef() * 2000;
412 private float getReleaseTime() {
413 return 15 + release.getValuef() * 3000;
416 private LinearEnvelope getEnvelope(int index) {
417 return cubeBrt[index % cubeBrt.length];
420 private SinLFO getBase(int index) {
421 return base[index % base.length];
424 public void noteOnReceived(Note note) {
425 LinearEnvelope env = getEnvelope(note.getPitch());
426 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
429 public void noteOffReceived(Note note) {
430 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
433 public void run(double deltaMs) {
435 float huef = lx.getBaseHuef();
436 float levelf = level.getValuef();
437 for (Cube c : model.cubes) {
438 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
440 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
448 class CrossSections extends SCPattern {
450 final SinLFO x = new SinLFO(0, model.xMax, 5000);
451 final SinLFO y = new SinLFO(0, model.yMax, 6000);
452 final SinLFO z = new SinLFO(0, model.zMax, 7000);
454 final BasicParameter xw = new BasicParameter("XWID", 0.3);
455 final BasicParameter yw = new BasicParameter("YWID", 0.3);
456 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
457 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
458 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
459 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
460 final BasicParameter xl = new BasicParameter("XLEV", 1);
461 final BasicParameter yl = new BasicParameter("YLEV", 1);
462 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
465 CrossSections(GLucose glucose) {
467 addModulator(x).trigger();
468 addModulator(y).trigger();
469 addModulator(z).trigger();
473 protected void addParams() {
485 void onParameterChanged(LXParameter p) {
487 x.setDuration(10000 - 8800*p.getValuef());
488 } else if (p == yr) {
489 y.setDuration(10000 - 9000*p.getValuef());
490 } else if (p == zr) {
491 z.setDuration(10000 - 9000*p.getValuef());
497 protected void updateXYZVals() {
503 public void run(double deltaMs) {
506 float xlv = 100*xl.getValuef();
507 float ylv = 100*yl.getValuef();
508 float zlv = 100*zl.getValuef();
510 float xwv = 100. / (10 + 40*xw.getValuef());
511 float ywv = 100. / (10 + 40*yw.getValuef());
512 float zwv = 100. / (10 + 40*zw.getValuef());
514 for (Point p : model.points) {
516 c = blendColor(c, color(
517 (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360,
518 constrain(140 - 1.1*abs(p.fx - model.xMax/2.), 0, 100),
519 max(0, xlv - xwv*abs(p.fx - xv))
521 c = blendColor(c, color(
522 (lx.getBaseHuef() + 80 + p.fy/10) % 360,
523 constrain(140 - 2.2*abs(p.fy - model.yMax/2.), 0, 100),
524 max(0, ylv - ywv*abs(p.fy - yv))
526 c = blendColor(c, color(
527 (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360,
528 constrain(140 - 2.2*abs(p.fz - model.zMax/2.), 0, 100),
529 max(0, zlv - zwv*abs(p.fz - zv))
536 class Blinders extends SCPattern {
541 final TriangleLFO hs;
543 public Blinders(GLucose glucose) {
546 for (int i = 0; i < m.length; ++i) {
547 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
549 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
550 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
551 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
552 s.modulateDurationBy(r);
555 public void run(double deltaMs) {
556 float hv = lx.getBaseHuef();
558 for (Strip strip : model.strips) {
560 float mv = m[si % m.length].getValuef();
561 for (Point p : strip.points) {
562 colors[p.index] = color(
563 (hv + p.fz + p.fy*hs.getValuef()) % 360,
564 min(100, abs(p.fx - s.getValuef())/2.),
565 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
574 class Psychedelia extends SCPattern {
577 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
578 SinLFO s = new SinLFO(-20, 147, 11000);
579 TriangleLFO h = new TriangleLFO(0, 240, 19000);
580 SinLFO c = new SinLFO(-.2, .8, 31000);
582 Psychedelia(GLucose glucose) {
584 addModulator(m).trigger();
585 addModulator(s).trigger();
586 addModulator(h).trigger();
587 addModulator(c).trigger();
590 void run(double deltaMs) {
591 float huev = h.getValuef();
592 float cv = c.getValuef();
593 float sv = s.getValuef();
594 float mv = m.getValuef();
596 for (Strip strip : model.strips) {
597 for (Point p : strip.points) {
598 colors[p.index] = color(
599 (huev + i*constrain(cv, 0, 2) + p.fz/2. + p.fx/4.) % 360,
600 min(100, abs(p.fy-sv)),
601 max(0, 100 - 50*abs((i%NUM) - mv))
609 class AskewPlanes extends SCPattern {
612 private final SinLFO a;
613 private final SinLFO b;
614 private final SinLFO c;
621 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
622 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
623 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
626 void run(double deltaMs) {
630 denom = sqrt(av*av + bv*bv);
634 final Plane[] planes;
635 final int NUM_PLANES = 3;
637 AskewPlanes(GLucose glucose) {
639 planes = new Plane[NUM_PLANES];
640 for (int i = 0; i < planes.length; ++i) {
641 planes[i] = new Plane(i);
645 public void run(double deltaMs) {
646 float huev = lx.getBaseHuef();
648 // This is super fucking bizarre. But if this is a for loop, the framerate
649 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
650 // Doesn't make ANY sense... there must be some weird side effect going on
651 // with the Processing internals perhaps?
652 // for (Plane plane : planes) {
653 // plane.run(deltaMs);
655 planes[0].run(deltaMs);
656 planes[1].run(deltaMs);
657 planes[2].run(deltaMs);
659 for (Point p : model.points) {
661 for (Plane plane : planes) {
662 if (plane.denom != 0) {
663 d = min(d, abs(plane.av*(p.fx-model.cx) + plane.bv*(p.fy-model.cy) + plane.cv) / plane.denom);
666 colors[p.index] = color(
667 (huev + abs(p.fx-model.cx)*.3 + p.fy*.8) % 360,
668 max(0, 100 - .8*abs(p.fx - model.cx)),
669 constrain(140 - 10.*d, 0, 100)
675 class ShiftingPlane extends SCPattern {
677 final SinLFO a = new SinLFO(-.2, .2, 5300);
678 final SinLFO b = new SinLFO(1, -1, 13300);
679 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
680 final SinLFO d = new SinLFO(-10, 10, 9500);
682 ShiftingPlane(GLucose glucose) {
684 addModulator(a).trigger();
685 addModulator(b).trigger();
686 addModulator(c).trigger();
687 addModulator(d).trigger();
690 public void run(double deltaMs) {
691 float hv = lx.getBaseHuef();
692 float av = a.getValuef();
693 float bv = b.getValuef();
694 float cv = c.getValuef();
695 float dv = d.getValuef();
696 float denom = sqrt(av*av + bv*bv + cv*cv);
697 for (Point p : model.points) {
698 float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom;
699 colors[p.index] = color(
700 (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360,
701 constrain(110 - d*6, 0, 100),
702 constrain(130 - 7*d, 0, 100)
708 class Traktor extends SCPattern {
710 final int FRAME_WIDTH = 60;
712 final BasicParameter speed = new BasicParameter("SPD", 0.5);
714 private float[] bass = new float[FRAME_WIDTH];
715 private float[] treble = new float[FRAME_WIDTH];
717 private int index = 0;
718 private GraphicEQ eq = null;
720 public Traktor(GLucose glucose) {
722 for (int i = 0; i < FRAME_WIDTH; ++i) {
729 public void onActive() {
731 eq = new GraphicEQ(lx, 16);
732 eq.slope.setValue(0.6);
733 eq.level.setValue(0.65);
734 eq.range.setValue(0.35);
735 eq.release.setValue(0.4);
736 addParameter(eq.level);
737 addParameter(eq.range);
738 addParameter(eq.attack);
739 addParameter(eq.release);
740 addParameter(eq.slope);
746 public void run(double deltaMs) {
749 int stepThresh = (int) (40 - 39*speed.getValuef());
751 if (counter < stepThresh) {
754 counter = counter % stepThresh;
756 index = (index + 1) % FRAME_WIDTH;
758 float rawBass = eq.getAverageLevel(0, 4);
759 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
761 bass[index] = rawBass * rawBass * rawBass * rawBass;
762 treble[index] = rawTreble * rawTreble;
764 for (Point p : model.points) {
765 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
766 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
768 colors[p.index] = color(
769 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
771 constrain(9 * (bass[pos]*model.cy - abs(p.fy - model.cy)), 0, 100)
773 colors[p.index] = blendColor(colors[p.index], color(
774 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
776 constrain(5 * (treble[pos]*.6*model.cy - abs(p.fy - model.cy)), 0, 100)
783 class ColorFuckerEffect extends SCEffect {
785 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
786 BasicParameter sat = new BasicParameter("SAT", 1);
787 BasicParameter bright = new BasicParameter("BRT", 1);
789 ColorFuckerEffect(GLucose glucose) {
791 addParameter(hueShift);
792 addParameter(bright);
796 public void doApply(int[] colors) {
800 float bMod = bright.getValuef();
801 float sMod = sat.getValuef();
802 float hMod = hueShift.getValuef();
803 if (bMod < 1 || sMod < 1 || hMod > 0) {
804 for (int i = 0; i < colors.length; ++i) {
806 (hue(colors[i]) + hueShift.getValuef()*360.) % 360,
807 saturation(colors[i]) * sat.getValuef(),
808 brightness(colors[i]) * bright.getValuef()
815 class BlurEffect extends SCEffect {
817 final LXParameter amount = new BasicParameter("AMT", 0);
819 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
821 BlurEffect(GLucose glucose) {
823 addParameter(amount);
825 frame = new int[lx.total];
826 for (int i = 0; i < frame.length; ++i) {
831 public void onEnable() {
832 env.setRangeFromHereTo(1, 400).start();
833 for (int i = 0; i < frame.length; ++i) {
838 public void onDisable() {
839 env.setRangeFromHereTo(0, 1000).start();
842 public void doApply(int[] colors) {
843 float amt = env.getValuef() * amount.getValuef();
846 amt = 1 - (amt*amt*amt);
847 for (int i = 0; i < colors.length; ++i) {
848 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
849 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);