1 class MidiMusic extends SCPattern {
3 private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
4 private final List<LightUp> allLights = new ArrayList<LightUp>();
6 private final Stack<LightUp> newLayers = new Stack<LightUp>();
8 MidiMusic(GLucose glucose) {
12 class LightUp extends LXLayer {
14 private LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
15 private Accelerator yPos = new Accelerator(0, 0, 0);
23 boolean isAvailable() {
24 return brt.getValuef() <= 0;
27 void noteOn(Note note) {
28 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 64) / 12., 0, 1));
29 yPos.setValue(lerp(20, model.yMax, note.getVelocity() / 127.));
30 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
33 void noteOff(Note note) {
34 yPos.setVelocity(0).setAcceleration(-380).start();
35 brt.setRangeFromHereTo(0, 1000).start();
38 public void run(double deltaMs, color[] colors) {
39 float bVal = brt.getValuef();
43 float yVal = yPos.getValuef();
44 for (Point p : model.points) {
45 float b = max(0, bVal - 3*dist(p.x, p.y, xPos, yVal));
47 colors[p.index] = blendColor(colors[p.index], lx.hsb(
48 (lx.getBaseHuef() + abs(p.x - model.cx) + abs(p.y - model.cy)) % 360,
57 public synchronized boolean noteOnReceived(Note note) {
58 if (note.getChannel() == 0) {
59 for (LightUp light : allLights) {
60 if (light.isAvailable()) {
62 lightMap.put(note.getPitch(), light);
66 LightUp newLight = new LightUp();
67 newLight.noteOn(note);
68 lightMap.put(note.getPitch(), newLight);
69 synchronized(newLayers) {
70 newLayers.push(newLight);
72 } else if (note.getChannel() == 1) {
77 public synchronized boolean noteOffReceived(Note note) {
78 if (note.getChannel() == 0) {
79 LightUp light = lightMap.get(note.getPitch());
87 public synchronized void run(double deltaMs) {
89 if (!newLayers.isEmpty()) {
90 synchronized(newLayers) {
91 while (!newLayers.isEmpty()) {
92 addLayer(newLayers.pop());
99 class Pulley extends SCPattern {
101 final int NUM_DIVISIONS = 16;
102 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
103 private final Click[] delays = new Click[NUM_DIVISIONS];
105 private final Click reset = new Click(9000);
106 private boolean isRising = false;
108 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
109 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
111 Pulley(GLucose glucose) {
113 for (int i = 0; i < NUM_DIVISIONS; ++i) {
114 addModulator(gravity[i] = new Accelerator(0, 0, 0));
115 addModulator(delays[i] = new Click(0));
117 addModulator(reset).start();
119 addParameter(beatAmount);
123 private void trigger() {
124 isRising = !isRising;
126 for (Accelerator g : gravity) {
128 g.setSpeed(random(20, 33), 0).start();
130 g.setVelocity(0).setAcceleration(-420);
131 delays[i].setDuration(random(0, 500)).trigger();
137 public void run(double deltaMs) {
142 // Fucking A, had to comment this all out because of that bizarre
143 // Processing bug where some simple loop takes an absurd amount of
144 // time, must be some pre-processor bug
145 // for (Accelerator g : gravity) {
146 // if (g.getValuef() > model.yMax) {
148 // } else if (g.getValuef() > model.yMax*.55) {
149 // if (g.getVelocityf() > 10) {
150 // g.setAcceleration(-16);
152 // g.setAcceleration(0);
158 for (Click d : delays) {
165 for (Accelerator g : gravity) {
166 if (g.getValuef() < 0) {
167 g.setValue(-g.getValuef());
168 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
173 float fPos = 1 - lx.tempo.rampf();
175 fPos = .2 + 4 * (.2 - fPos);
177 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
178 for (Point p : model.points) {
179 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
180 colors[p.index] = lx.hsb(
181 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
182 constrain(130 - p.y*.8, 0, 100),
183 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
189 class ViolinWave extends SCPattern {
191 BasicParameter level = new BasicParameter("LVL", 0.45);
192 BasicParameter range = new BasicParameter("RNG", 0.5);
193 BasicParameter edge = new BasicParameter("EDG", 0.5);
194 BasicParameter release = new BasicParameter("RLS", 0.5);
195 BasicParameter speed = new BasicParameter("SPD", 0.5);
196 BasicParameter amp = new BasicParameter("AMP", 0.25);
197 BasicParameter period = new BasicParameter("WAVE", 0.5);
198 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
199 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
200 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
202 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
204 ViolinWave(GLucose glucose) {
209 addParameter(release);
212 addParameter(period);
214 addParameter(pSpeed);
215 addParameter(pDensity);
217 addModulator(dbValue);
220 final List<Particle> particles = new ArrayList<Particle>();
224 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
225 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
232 Particle trigger(boolean direction) {
233 float xInit = random(model.xMin, model.xMax);
234 float time = 3000 - 2500*pSpeed.getValuef();
235 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
236 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
241 return x.isRunning() || y.isRunning();
244 public void run(double deltaMs) {
249 float pFalloff = (30 - 27*pSize.getValuef());
250 for (Point p : model.points) {
251 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
253 colors[p.index] = blendColor(colors[p.index], lx.hsb(
254 lx.getBaseHuef(), 20, b
261 float[] centers = new float[30];
263 boolean rising = true;
265 void fireParticle(boolean direction) {
266 boolean gotOne = false;
267 for (Particle p : particles) {
269 p.trigger(direction);
273 particles.add(new Particle().trigger(direction));
276 public void run(double deltaMs) {
277 accum += deltaMs / (1000. - 900.*speed.getValuef());
278 for (int i = 0; i < centers.length; ++i) {
279 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
282 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
283 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
284 if (dB > dbValue.getValuef()) {
286 dbValue.setRangeFromHereTo(dB, 10).trigger();
289 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
295 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
297 float edg = 1 + edge.getValuef() * 40;
298 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
299 float val = max(2, dbValue.getValuef());
301 for (Point p : model.points) {
302 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
303 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
304 colors[p.index] = lx.hsb(
305 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
306 min(100, 20 + 8*abs(p.y - centers[ci])),
307 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
311 for (Particle p : particles) {
317 class BouncyBalls extends SCPattern {
319 static final int NUM_BALLS = 6;
324 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
328 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
329 addModulator(yPos = new Accelerator(0, 0, 0));
330 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
333 void bounce(float midiVel) {
334 float v = 100 + 8*midiVel;
335 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
338 float getAccel(float v, float oneBeat) {
339 return -2*v / oneBeat;
342 void run(double deltaMs) {
343 float flrLevel = flr.getValuef() * model.xMax/2.;
344 if (yPos.getValuef() < flrLevel) {
345 if (yPos.getVelocity() < -50) {
346 yPos.setValue(2*flrLevel-yPos.getValuef());
347 float v = -yPos.getVelocityf() * bounce.getValuef();
348 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
350 yPos.setValue(flrLevel).stop();
353 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
354 float xv = xPos.getValuef();
355 float yv = yPos.getValuef();
357 for (Point p : model.points) {
358 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
359 float b = constrain(130 - falloff*d, 0, 100);
361 colors[p.index] = blendColor(colors[p.index], lx.hsb(
362 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
363 max(0, 100 - .45*(p.y - flrLevel)),
371 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
373 final BasicParameter bounce = new BasicParameter("BNC", .8);
374 final BasicParameter flr = new BasicParameter("FLR", 0);
375 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
377 BouncyBalls(GLucose glucose) {
379 for (int i = 0; i < balls.length; ++i) {
380 balls[i] = new BouncyBall(i);
382 addParameter(bounce);
384 addParameter(blobSize);
387 public void run(double deltaMs) {
389 for (BouncyBall b : balls) {
394 public boolean noteOnReceived(Note note) {
395 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
396 balls[pitch].bounce(note.getVelocity());
401 class SpaceTime extends SCPattern {
403 SinLFO pos = new SinLFO(0, 1, 3000);
404 SinLFO rate = new SinLFO(1000, 9000, 13000);
405 SinLFO falloff = new SinLFO(10, 70, 5000);
408 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
409 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
412 public SpaceTime(GLucose glucose) {
415 addModulator(pos).trigger();
416 addModulator(rate).trigger();
417 addModulator(falloff).trigger();
418 pos.modulateDurationBy(rate);
419 addParameter(rateParameter);
420 addParameter(sizeParameter);
423 public void onParameterChanged(LXParameter parameter) {
424 if (parameter == rateParameter) {
425 rate.stop().setValue(9000 - 8000*parameter.getValuef());
426 } else if (parameter == sizeParameter) {
427 falloff.stop().setValue(70 - 60*parameter.getValuef());
431 void run(double deltaMs) {
432 angle += deltaMs * 0.0007;
433 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
434 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
436 float pVal = pos.getValuef();
437 float fVal = falloff.getValuef();
440 for (Strip strip : model.strips) {
442 for (Point p : strip.points) {
443 colors[p.index] = lx.hsb(
444 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
445 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
446 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
455 class Swarm extends SCPattern {
457 SawLFO offset = new SawLFO(0, 1, 1000);
458 SinLFO rate = new SinLFO(350, 1200, 63000);
459 SinLFO falloff = new SinLFO(15, 50, 17000);
460 SinLFO fX = new SinLFO(0, model.xMax, 19000);
461 SinLFO fY = new SinLFO(0, model.yMax, 11000);
462 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
464 public Swarm(GLucose glucose) {
467 addModulator(offset).trigger();
468 addModulator(rate).trigger();
469 addModulator(falloff).trigger();
470 addModulator(fX).trigger();
471 addModulator(fY).trigger();
472 addModulator(hOffX).trigger();
473 offset.modulateDurationBy(rate);
476 float modDist(float v1, float v2, float mod) {
480 return min(v2-v1, v1+mod-v2);
483 return min(v1-v2, v2+mod-v1);
487 void run(double deltaMs) {
489 for (Strip strip : model.strips ) {
491 for (Point p : strip.points) {
492 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
493 colors[p.index] = lx.hsb(
494 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
495 constrain(80 + 40 * fV, 0, 100),
496 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
505 class SwipeTransition extends SCTransition {
507 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
509 SwipeTransition(GLucose glucose) {
515 void computeBlend(int[] c1, int[] c2, double progress) {
516 float bleedf = 10 + bleed.getValuef() * 200.;
517 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
518 for (Point p : model.points) {
519 float d = (p.x - xPos) / bleedf;
521 colors[p.index] = c2[p.index];
523 colors[p.index] = c1[p.index];
525 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
531 abstract class BlendTransition extends SCTransition {
535 BlendTransition(GLucose glucose, int blendType) {
537 this.blendType = blendType;
540 void computeBlend(int[] c1, int[] c2, double progress) {
541 if (progress < 0.5) {
542 for (int i = 0; i < c1.length; ++i) {
543 colors[i] = lerpColor(
545 blendColor(c1[i], c2[i], blendType),
546 (float) (2.*progress),
550 for (int i = 0; i < c1.length; ++i) {
551 colors[i] = lerpColor(
553 blendColor(c1[i], c2[i], blendType),
554 (float) (2.*(1. - progress)),
561 class MultiplyTransition extends BlendTransition {
562 MultiplyTransition(GLucose glucose) {
563 super(glucose, MULTIPLY);
567 class ScreenTransition extends BlendTransition {
568 ScreenTransition(GLucose glucose) {
569 super(glucose, SCREEN);
573 class BurnTransition extends BlendTransition {
574 BurnTransition(GLucose glucose) {
575 super(glucose, BURN);
579 class DodgeTransition extends BlendTransition {
580 DodgeTransition(GLucose glucose) {
581 super(glucose, DODGE);
585 class OverlayTransition extends BlendTransition {
586 OverlayTransition(GLucose glucose) {
587 super(glucose, OVERLAY);
591 class AddTransition extends BlendTransition {
592 AddTransition(GLucose glucose) {
597 class SubtractTransition extends BlendTransition {
598 SubtractTransition(GLucose glucose) {
599 super(glucose, SUBTRACT);
603 class SoftLightTransition extends BlendTransition {
604 SoftLightTransition(GLucose glucose) {
605 super(glucose, SOFT_LIGHT);
609 class BassPod extends SCPattern {
611 private GraphicEQ eq = null;
613 public BassPod(GLucose glucose) {
617 protected void onActive() {
619 eq = new GraphicEQ(lx, 16);
620 eq.slope.setValue(0.6);
621 addParameter(eq.level);
622 addParameter(eq.range);
623 addParameter(eq.attack);
624 addParameter(eq.release);
625 addParameter(eq.slope);
629 public void run(double deltaMs) {
632 float bassLevel = eq.getAverageLevel(0, 5);
634 for (Point p : model.points) {
635 int avgIndex = (int) constrain(1 + abs(p.x-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
637 for (int i = avgIndex; i < avgIndex + 5; ++i) {
638 value += eq.getLevel(i);
642 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
643 colors[p.index] = lx.hsb(
644 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
645 constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
653 class CubeEQ extends SCPattern {
655 private GraphicEQ eq = null;
657 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
658 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
659 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
661 public CubeEQ(GLucose glucose) {
665 protected void onActive() {
667 eq = new GraphicEQ(lx, 16);
668 addParameter(eq.level);
669 addParameter(eq.range);
670 addParameter(eq.attack);
671 addParameter(eq.release);
672 addParameter(eq.slope);
675 addParameter(blockiness);
679 public void run(double deltaMs) {
682 float edgeConst = 2 + 30*edge.getValuef();
683 float clrConst = 1.1 + clr.getValuef();
685 for (Point p : model.points) {
686 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
687 int avgFloor = (int) avgIndex;
689 float leftVal = eq.getLevel(avgFloor);
690 float rightVal = eq.getLevel(avgFloor+1);
691 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
693 float chunkyValue = (
694 eq.getLevel(avgFloor/4*4) +
695 eq.getLevel(avgFloor/4*4 + 1) +
696 eq.getLevel(avgFloor/4*4 + 2) +
697 eq.getLevel(avgFloor/4*4 + 3)
700 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
702 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
703 colors[p.index] = lx.hsb(
704 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
712 class BoomEffect extends SCEffect {
714 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
715 final BasicParameter speed = new BasicParameter("SPD", 0.5);
716 final BasicParameter bright = new BasicParameter("BRT", 1.0);
717 final BasicParameter sat = new BasicParameter("SAT", 0.2);
718 List<Layer> layers = new ArrayList<Layer>();
719 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
722 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
730 float falloffv = falloffv();
731 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
735 void doApply(int[] colors) {
736 float brightv = 100 * bright.getValuef();
737 float falloffv = falloffv();
738 float satv = sat.getValuef() * 100;
739 float huev = lx.getBaseHuef();
740 for (Point p : model.points) {
741 colors[p.index] = blendColor(
743 lx.hsb(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.x, 2*p.y, 3*p.z, model.xMax/2, model.yMax, model.zMax*1.5)), 0, 100)),
749 BoomEffect(GLucose glucose) {
750 super(glucose, true);
751 addParameter(falloff);
753 addParameter(bright);
757 public void onEnable() {
758 for (Layer l : layers) {
759 if (!l.boom.isRunning()) {
764 layers.add(new Layer());
767 private float falloffv() {
768 return 20 - 19 * falloff.getValuef();
771 public void onTrigger() {
775 public void doApply(int[] colors) {
776 for (Layer l : layers) {
777 if (l.boom.isRunning()) {
784 public class PianoKeyPattern extends SCPattern {
786 final LinearEnvelope[] cubeBrt;
788 final BasicParameter attack = new BasicParameter("ATK", 0.1);
789 final BasicParameter release = new BasicParameter("REL", 0.5);
790 final BasicParameter level = new BasicParameter("AMB", 0.6);
792 PianoKeyPattern(GLucose glucose) {
795 addParameter(attack);
796 addParameter(release);
798 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
799 for (int i = 0; i < cubeBrt.length; ++i) {
800 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
802 base = new SinLFO[model.cubes.size() / 12];
803 for (int i = 0; i < base.length; ++i) {
804 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
808 private float getAttackTime() {
809 return 15 + attack.getValuef()*attack.getValuef() * 2000;
812 private float getReleaseTime() {
813 return 15 + release.getValuef() * 3000;
816 private LinearEnvelope getEnvelope(int index) {
817 return cubeBrt[index % cubeBrt.length];
820 private SinLFO getBase(int index) {
821 return base[index % base.length];
824 public boolean noteOnReceived(Note note) {
825 LinearEnvelope env = getEnvelope(note.getPitch());
826 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
830 public boolean noteOffReceived(Note note) {
831 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
835 public void run(double deltaMs) {
837 float huef = lx.getBaseHuef();
838 float levelf = level.getValuef();
839 for (Cube c : model.cubes) {
840 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
842 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
850 class CrossSections extends SCPattern {
852 final SinLFO x = new SinLFO(0, model.xMax, 5000);
853 final SinLFO y = new SinLFO(0, model.yMax, 6000);
854 final SinLFO z = new SinLFO(0, model.zMax, 7000);
856 final BasicParameter xw = new BasicParameter("XWID", 0.3);
857 final BasicParameter yw = new BasicParameter("YWID", 0.3);
858 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
859 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
860 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
861 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
862 final BasicParameter xl = new BasicParameter("XLEV", 1);
863 final BasicParameter yl = new BasicParameter("YLEV", 1);
864 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
867 CrossSections(GLucose glucose) {
869 addModulator(x).trigger();
870 addModulator(y).trigger();
871 addModulator(z).trigger();
875 protected void addParams() {
887 void onParameterChanged(LXParameter p) {
889 x.setDuration(10000 - 8800*p.getValuef());
890 } else if (p == yr) {
891 y.setDuration(10000 - 9000*p.getValuef());
892 } else if (p == zr) {
893 z.setDuration(10000 - 9000*p.getValuef());
899 protected void updateXYZVals() {
905 public void run(double deltaMs) {
908 float xlv = 100*xl.getValuef();
909 float ylv = 100*yl.getValuef();
910 float zlv = 100*zl.getValuef();
912 float xwv = 100. / (10 + 40*xw.getValuef());
913 float ywv = 100. / (10 + 40*yw.getValuef());
914 float zwv = 100. / (10 + 40*zw.getValuef());
916 for (Point p : model.points) {
918 c = blendColor(c, lx.hsb(
919 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
920 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
921 max(0, xlv - xwv*abs(p.x - xv))
923 c = blendColor(c, lx.hsb(
924 (lx.getBaseHuef() + 80 + p.y/10) % 360,
925 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
926 max(0, ylv - ywv*abs(p.y - yv))
928 c = blendColor(c, lx.hsb(
929 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
930 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
931 max(0, zlv - zwv*abs(p.z - zv))
938 class Blinders extends SCPattern {
943 final TriangleLFO hs;
945 public Blinders(GLucose glucose) {
948 for (int i = 0; i < m.length; ++i) {
949 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
951 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
952 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
953 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
954 s.modulateDurationBy(r);
957 public void run(double deltaMs) {
958 float hv = lx.getBaseHuef();
960 for (Strip strip : model.strips) {
962 float mv = m[si % m.length].getValuef();
963 for (Point p : strip.points) {
964 colors[p.index] = lx.hsb(
965 (hv + p.z + p.y*hs.getValuef()) % 360,
966 min(100, abs(p.x - s.getValuef())/2.),
967 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
976 class Psychedelia extends SCPattern {
979 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
980 SinLFO s = new SinLFO(-20, 147, 11000);
981 TriangleLFO h = new TriangleLFO(0, 240, 19000);
982 SinLFO c = new SinLFO(-.2, .8, 31000);
984 Psychedelia(GLucose glucose) {
986 addModulator(m).trigger();
987 addModulator(s).trigger();
988 addModulator(h).trigger();
989 addModulator(c).trigger();
992 void run(double deltaMs) {
993 float huev = h.getValuef();
994 float cv = c.getValuef();
995 float sv = s.getValuef();
996 float mv = m.getValuef();
998 for (Strip strip : model.strips) {
999 for (Point p : strip.points) {
1000 colors[p.index] = lx.hsb(
1001 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1002 min(100, abs(p.y-sv)),
1003 max(0, 100 - 50*abs((i%NUM) - mv))
1011 class AskewPlanes extends SCPattern {
1014 private final SinLFO a;
1015 private final SinLFO b;
1016 private final SinLFO c;
1023 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1024 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1025 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1028 void run(double deltaMs) {
1032 denom = sqrt(av*av + bv*bv);
1036 final Plane[] planes;
1037 final int NUM_PLANES = 3;
1039 AskewPlanes(GLucose glucose) {
1041 planes = new Plane[NUM_PLANES];
1042 for (int i = 0; i < planes.length; ++i) {
1043 planes[i] = new Plane(i);
1047 public void run(double deltaMs) {
1048 float huev = lx.getBaseHuef();
1050 // This is super fucking bizarre. But if this is a for loop, the framerate
1051 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1052 // Doesn't make ANY sense... there must be some weird side effect going on
1053 // with the Processing internals perhaps?
1054 // for (Plane plane : planes) {
1055 // plane.run(deltaMs);
1057 planes[0].run(deltaMs);
1058 planes[1].run(deltaMs);
1059 planes[2].run(deltaMs);
1061 for (Point p : model.points) {
1062 float d = MAX_FLOAT;
1063 for (Plane plane : planes) {
1064 if (plane.denom != 0) {
1065 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1068 colors[p.index] = lx.hsb(
1069 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1070 max(0, 100 - .8*abs(p.x - model.cx)),
1071 constrain(140 - 10.*d, 0, 100)
1077 class ShiftingPlane extends SCPattern {
1079 final SinLFO a = new SinLFO(-.2, .2, 5300);
1080 final SinLFO b = new SinLFO(1, -1, 13300);
1081 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1082 final SinLFO d = new SinLFO(-10, 10, 9500);
1084 ShiftingPlane(GLucose glucose) {
1086 addModulator(a).trigger();
1087 addModulator(b).trigger();
1088 addModulator(c).trigger();
1089 addModulator(d).trigger();
1092 public void run(double deltaMs) {
1093 float hv = lx.getBaseHuef();
1094 float av = a.getValuef();
1095 float bv = b.getValuef();
1096 float cv = c.getValuef();
1097 float dv = d.getValuef();
1098 float denom = sqrt(av*av + bv*bv + cv*cv);
1099 for (Point p : model.points) {
1100 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1101 colors[p.index] = lx.hsb(
1102 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1103 constrain(110 - d*6, 0, 100),
1104 constrain(130 - 7*d, 0, 100)
1110 class Traktor extends SCPattern {
1112 final int FRAME_WIDTH = 60;
1114 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1116 private float[] bass = new float[FRAME_WIDTH];
1117 private float[] treble = new float[FRAME_WIDTH];
1119 private int index = 0;
1120 private GraphicEQ eq = null;
1122 public Traktor(GLucose glucose) {
1124 for (int i = 0; i < FRAME_WIDTH; ++i) {
1128 addParameter(speed);
1131 public void onActive() {
1133 eq = new GraphicEQ(lx, 16);
1134 eq.slope.setValue(0.6);
1135 eq.level.setValue(0.65);
1136 eq.range.setValue(0.35);
1137 eq.release.setValue(0.4);
1138 addParameter(eq.level);
1139 addParameter(eq.range);
1140 addParameter(eq.attack);
1141 addParameter(eq.release);
1142 addParameter(eq.slope);
1148 public void run(double deltaMs) {
1151 int stepThresh = (int) (40 - 39*speed.getValuef());
1153 if (counter < stepThresh) {
1156 counter = counter % stepThresh;
1158 index = (index + 1) % FRAME_WIDTH;
1160 float rawBass = eq.getAverageLevel(0, 4);
1161 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1163 bass[index] = rawBass * rawBass * rawBass * rawBass;
1164 treble[index] = rawTreble * rawTreble;
1166 for (Point p : model.points) {
1167 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1168 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1170 colors[p.index] = lx.hsb(
1171 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1173 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100)
1175 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1176 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1178 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1185 class ColorFuckerEffect extends SCEffect {
1187 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1188 BasicParameter sat = new BasicParameter("SAT", 1);
1189 BasicParameter bright = new BasicParameter("BRT", 1);
1190 float[] hsb = new float[3];
1192 ColorFuckerEffect(GLucose glucose) {
1194 addParameter(hueShift);
1195 addParameter(bright);
1199 public void doApply(int[] colors) {
1203 float bMod = bright.getValuef();
1204 float sMod = sat.getValuef();
1205 float hMod = hueShift.getValuef();
1206 if (bMod < 1 || sMod < 1 || hMod > 0) {
1207 for (int i = 0; i < colors.length; ++i) {
1208 lx.RGBtoHSB(colors[i], hsb);
1210 (360. * hsb[0] + hueShift.getValuef()*360.) % 360,
1211 100. * hsb[1] * sat.getValuef(),
1212 100. * hsb[2] * bright.getValuef()
1219 class BlurEffect extends SCEffect {
1221 final LXParameter amount = new BasicParameter("AMT", 0);
1223 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1225 BlurEffect(GLucose glucose) {
1227 addParameter(amount);
1229 frame = new int[lx.total];
1230 for (int i = 0; i < frame.length; ++i) {
1235 public void onEnable() {
1236 env.setRangeFromHereTo(1, 400).start();
1237 for (int i = 0; i < frame.length; ++i) {
1242 public void onDisable() {
1243 env.setRangeFromHereTo(0, 1000).start();
1246 public void doApply(int[] colors) {
1247 float amt = env.getValuef() * amount.getValuef();
1250 amt = 1 - (amt*amt*amt);
1251 for (int i = 0; i < colors.length; ++i) {
1252 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1253 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);