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.1);
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(40, 50), 0).start();
130 g.setVelocity(0).setAcceleration(-420);
131 delays[i].setDuration(random(0, 500)).trigger();
137 public void run(double deltaMs) {
142 for (Click d : delays) {
150 for (Accelerator g : gravity) {
152 if (g.getValuef() > model.yMax) {
154 } else if (g.getValuef() > model.yMax*.55) {
155 if (g.getVelocityf() > 10) {
156 g.setAcceleration(-16);
158 g.setAcceleration(0);
162 if (g.getValuef() < 0) {
163 g.setValue(-g.getValuef());
164 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
169 float fPos = 1 - lx.tempo.rampf();
171 fPos = .2 + 4 * (.2 - fPos);
173 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
174 for (Point p : model.points) {
175 int g = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
176 colors[p.index] = lx.hsb(
177 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
178 constrain(130 - p.y*.8, 0, 100),
179 max(0, 100 - abs(p.y - gravity[g].getValuef())*falloff)
185 class ViolinWave extends SCPattern {
187 BasicParameter level = new BasicParameter("LVL", 0.45);
188 BasicParameter range = new BasicParameter("RNG", 0.5);
189 BasicParameter edge = new BasicParameter("EDG", 0.5);
190 BasicParameter release = new BasicParameter("RLS", 0.5);
191 BasicParameter speed = new BasicParameter("SPD", 0.5);
192 BasicParameter amp = new BasicParameter("AMP", 0.25);
193 BasicParameter period = new BasicParameter("WAVE", 0.5);
194 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
195 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
196 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
198 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
200 ViolinWave(GLucose glucose) {
205 addParameter(release);
208 addParameter(period);
210 addParameter(pSpeed);
211 addParameter(pDensity);
213 addModulator(dbValue);
216 final List<Particle> particles = new ArrayList<Particle>();
220 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
221 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
228 Particle trigger(boolean direction) {
229 float xInit = random(model.xMin, model.xMax);
230 float time = 3000 - 2500*pSpeed.getValuef();
231 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
232 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
237 return x.isRunning() || y.isRunning();
240 public void run(double deltaMs) {
245 float pFalloff = (30 - 27*pSize.getValuef());
246 for (Point p : model.points) {
247 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
249 colors[p.index] = blendColor(colors[p.index], lx.hsb(
250 lx.getBaseHuef(), 20, b
257 float[] centers = new float[30];
259 boolean rising = true;
261 void fireParticle(boolean direction) {
262 boolean gotOne = false;
263 for (Particle p : particles) {
265 p.trigger(direction);
269 particles.add(new Particle().trigger(direction));
272 public void run(double deltaMs) {
273 accum += deltaMs / (1000. - 900.*speed.getValuef());
274 for (int i = 0; i < centers.length; ++i) {
275 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
278 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
279 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
280 if (dB > dbValue.getValuef()) {
282 dbValue.setRangeFromHereTo(dB, 10).trigger();
285 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
291 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
293 float edg = 1 + edge.getValuef() * 40;
294 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
295 float val = max(2, dbValue.getValuef());
297 for (Point p : model.points) {
298 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
299 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
300 colors[p.index] = lx.hsb(
301 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
302 min(100, 20 + 8*abs(p.y - centers[ci])),
303 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
307 for (Particle p : particles) {
313 class BouncyBalls extends SCPattern {
315 static final int NUM_BALLS = 6;
320 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
324 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
325 addModulator(yPos = new Accelerator(0, 0, 0));
326 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
329 void bounce(float midiVel) {
330 float v = 100 + 8*midiVel;
331 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
334 float getAccel(float v, float oneBeat) {
335 return -2*v / oneBeat;
338 void run(double deltaMs) {
339 float flrLevel = flr.getValuef() * model.xMax/2.;
340 if (yPos.getValuef() < flrLevel) {
341 if (yPos.getVelocity() < -50) {
342 yPos.setValue(2*flrLevel-yPos.getValuef());
343 float v = -yPos.getVelocityf() * bounce.getValuef();
344 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
346 yPos.setValue(flrLevel).stop();
349 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
350 float xv = xPos.getValuef();
351 float yv = yPos.getValuef();
353 for (Point p : model.points) {
354 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
355 float b = constrain(130 - falloff*d, 0, 100);
357 colors[p.index] = blendColor(colors[p.index], lx.hsb(
358 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
359 max(0, 100 - .45*(p.y - flrLevel)),
367 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
369 final BasicParameter bounce = new BasicParameter("BNC", .8);
370 final BasicParameter flr = new BasicParameter("FLR", 0);
371 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
373 BouncyBalls(GLucose glucose) {
375 for (int i = 0; i < balls.length; ++i) {
376 balls[i] = new BouncyBall(i);
378 addParameter(bounce);
380 addParameter(blobSize);
383 public void run(double deltaMs) {
385 for (BouncyBall b : balls) {
390 public boolean noteOnReceived(Note note) {
391 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
392 balls[pitch].bounce(note.getVelocity());
397 class SpaceTime extends SCPattern {
399 SinLFO pos = new SinLFO(0, 1, 3000);
400 SinLFO rate = new SinLFO(1000, 9000, 13000);
401 SinLFO falloff = new SinLFO(10, 70, 5000);
404 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
405 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
408 public SpaceTime(GLucose glucose) {
411 addModulator(pos).trigger();
412 addModulator(rate).trigger();
413 addModulator(falloff).trigger();
414 pos.modulateDurationBy(rate);
415 addParameter(rateParameter);
416 addParameter(sizeParameter);
419 public void onParameterChanged(LXParameter parameter) {
420 if (parameter == rateParameter) {
421 rate.stop().setValue(9000 - 8000*parameter.getValuef());
422 } else if (parameter == sizeParameter) {
423 falloff.stop().setValue(70 - 60*parameter.getValuef());
427 void run(double deltaMs) {
428 angle += deltaMs * 0.0007;
429 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
430 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
432 float pVal = pos.getValuef();
433 float fVal = falloff.getValuef();
436 for (Strip strip : model.strips) {
438 for (Point p : strip.points) {
439 colors[p.index] = lx.hsb(
440 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
441 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
442 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
451 class Swarm extends SCPattern {
453 SawLFO offset = new SawLFO(0, 1, 1000);
454 SinLFO rate = new SinLFO(350, 1200, 63000);
455 SinLFO falloff = new SinLFO(15, 50, 17000);
456 SinLFO fX = new SinLFO(0, model.xMax, 19000);
457 SinLFO fY = new SinLFO(0, model.yMax, 11000);
458 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
460 public Swarm(GLucose glucose) {
463 addModulator(offset).trigger();
464 addModulator(rate).trigger();
465 addModulator(falloff).trigger();
466 addModulator(fX).trigger();
467 addModulator(fY).trigger();
468 addModulator(hOffX).trigger();
469 offset.modulateDurationBy(rate);
472 float modDist(float v1, float v2, float mod) {
476 return min(v2-v1, v1+mod-v2);
479 return min(v1-v2, v2+mod-v1);
483 void run(double deltaMs) {
485 for (Strip strip : model.strips ) {
487 for (Point p : strip.points) {
488 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
489 colors[p.index] = lx.hsb(
490 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
491 constrain(80 + 40 * fV, 0, 100),
492 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
501 class SwipeTransition extends SCTransition {
503 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
505 SwipeTransition(GLucose glucose) {
511 void computeBlend(int[] c1, int[] c2, double progress) {
512 float bleedf = 10 + bleed.getValuef() * 200.;
513 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
514 for (Point p : model.points) {
515 float d = (p.x - xPos) / bleedf;
517 colors[p.index] = c2[p.index];
519 colors[p.index] = c1[p.index];
521 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
527 abstract class BlendTransition extends SCTransition {
531 BlendTransition(GLucose glucose, int blendType) {
533 this.blendType = blendType;
536 void computeBlend(int[] c1, int[] c2, double progress) {
537 if (progress < 0.5) {
538 for (int i = 0; i < c1.length; ++i) {
539 colors[i] = lerpColor(
541 blendColor(c1[i], c2[i], blendType),
542 (float) (2.*progress),
546 for (int i = 0; i < c1.length; ++i) {
547 colors[i] = lerpColor(
549 blendColor(c1[i], c2[i], blendType),
550 (float) (2.*(1. - progress)),
557 class MultiplyTransition extends BlendTransition {
558 MultiplyTransition(GLucose glucose) {
559 super(glucose, MULTIPLY);
563 class ScreenTransition extends BlendTransition {
564 ScreenTransition(GLucose glucose) {
565 super(glucose, SCREEN);
569 class BurnTransition extends BlendTransition {
570 BurnTransition(GLucose glucose) {
571 super(glucose, BURN);
575 class DodgeTransition extends BlendTransition {
576 DodgeTransition(GLucose glucose) {
577 super(glucose, DODGE);
581 class OverlayTransition extends BlendTransition {
582 OverlayTransition(GLucose glucose) {
583 super(glucose, OVERLAY);
587 class AddTransition extends BlendTransition {
588 AddTransition(GLucose glucose) {
593 class SubtractTransition extends BlendTransition {
594 SubtractTransition(GLucose glucose) {
595 super(glucose, SUBTRACT);
599 class SoftLightTransition extends BlendTransition {
600 SoftLightTransition(GLucose glucose) {
601 super(glucose, SOFT_LIGHT);
605 class BassPod extends SCPattern {
607 private GraphicEQ eq = null;
609 public BassPod(GLucose glucose) {
613 protected void onActive() {
615 eq = new GraphicEQ(lx, 16);
616 eq.slope.setValue(0.6);
617 addParameter(eq.level);
618 addParameter(eq.range);
619 addParameter(eq.attack);
620 addParameter(eq.release);
621 addParameter(eq.slope);
625 public void run(double deltaMs) {
628 float bassLevel = eq.getAverageLevel(0, 5);
630 for (Point p : model.points) {
631 int avgIndex = (int) constrain(1 + abs(p.x-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
633 for (int i = avgIndex; i < avgIndex + 5; ++i) {
634 value += eq.getLevel(i);
638 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
639 colors[p.index] = lx.hsb(
640 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
641 constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
649 class CubeEQ extends SCPattern {
651 private GraphicEQ eq = null;
653 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
654 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
655 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
657 public CubeEQ(GLucose glucose) {
661 protected void onActive() {
663 eq = new GraphicEQ(lx, 16);
664 addParameter(eq.level);
665 addParameter(eq.range);
666 addParameter(eq.attack);
667 addParameter(eq.release);
668 addParameter(eq.slope);
671 addParameter(blockiness);
675 public void run(double deltaMs) {
678 float edgeConst = 2 + 30*edge.getValuef();
679 float clrConst = 1.1 + clr.getValuef();
681 for (Point p : model.points) {
682 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
683 int avgFloor = (int) avgIndex;
685 float leftVal = eq.getLevel(avgFloor);
686 float rightVal = eq.getLevel(avgFloor+1);
687 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
689 float chunkyValue = (
690 eq.getLevel(avgFloor/4*4) +
691 eq.getLevel(avgFloor/4*4 + 1) +
692 eq.getLevel(avgFloor/4*4 + 2) +
693 eq.getLevel(avgFloor/4*4 + 3)
696 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
698 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
699 colors[p.index] = lx.hsb(
700 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
708 class BoomEffect extends SCEffect {
710 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
711 final BasicParameter speed = new BasicParameter("SPD", 0.5);
712 final BasicParameter bright = new BasicParameter("BRT", 1.0);
713 final BasicParameter sat = new BasicParameter("SAT", 0.2);
714 List<Layer> layers = new ArrayList<Layer>();
715 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
718 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
726 float falloffv = falloffv();
727 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
731 void doApply(int[] colors) {
732 float brightv = 100 * bright.getValuef();
733 float falloffv = falloffv();
734 float satv = sat.getValuef() * 100;
735 float huev = lx.getBaseHuef();
736 for (Point p : model.points) {
737 colors[p.index] = blendColor(
739 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)),
745 BoomEffect(GLucose glucose) {
746 super(glucose, true);
747 addParameter(falloff);
749 addParameter(bright);
753 public void onEnable() {
754 for (Layer l : layers) {
755 if (!l.boom.isRunning()) {
760 layers.add(new Layer());
763 private float falloffv() {
764 return 20 - 19 * falloff.getValuef();
767 public void onTrigger() {
771 public void doApply(int[] colors) {
772 for (Layer l : layers) {
773 if (l.boom.isRunning()) {
780 public class PianoKeyPattern extends SCPattern {
782 final LinearEnvelope[] cubeBrt;
784 final BasicParameter attack = new BasicParameter("ATK", 0.1);
785 final BasicParameter release = new BasicParameter("REL", 0.5);
786 final BasicParameter level = new BasicParameter("AMB", 0.6);
788 PianoKeyPattern(GLucose glucose) {
791 addParameter(attack);
792 addParameter(release);
794 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
795 for (int i = 0; i < cubeBrt.length; ++i) {
796 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
798 base = new SinLFO[model.cubes.size() / 12];
799 for (int i = 0; i < base.length; ++i) {
800 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
804 private float getAttackTime() {
805 return 15 + attack.getValuef()*attack.getValuef() * 2000;
808 private float getReleaseTime() {
809 return 15 + release.getValuef() * 3000;
812 private LinearEnvelope getEnvelope(int index) {
813 return cubeBrt[index % cubeBrt.length];
816 private SinLFO getBase(int index) {
817 return base[index % base.length];
820 public boolean noteOnReceived(Note note) {
821 LinearEnvelope env = getEnvelope(note.getPitch());
822 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
826 public boolean noteOffReceived(Note note) {
827 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
831 public void run(double deltaMs) {
833 float huef = lx.getBaseHuef();
834 float levelf = level.getValuef();
835 for (Cube c : model.cubes) {
836 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
838 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
846 class CrossSections extends SCPattern {
848 final SinLFO x = new SinLFO(0, model.xMax, 5000);
849 final SinLFO y = new SinLFO(0, model.yMax, 6000);
850 final SinLFO z = new SinLFO(0, model.zMax, 7000);
852 final BasicParameter xw = new BasicParameter("XWID", 0.3);
853 final BasicParameter yw = new BasicParameter("YWID", 0.3);
854 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
855 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
856 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
857 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
858 final BasicParameter xl = new BasicParameter("XLEV", 1);
859 final BasicParameter yl = new BasicParameter("YLEV", 1);
860 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
863 CrossSections(GLucose glucose) {
865 addModulator(x).trigger();
866 addModulator(y).trigger();
867 addModulator(z).trigger();
871 protected void addParams() {
883 void onParameterChanged(LXParameter p) {
885 x.setDuration(10000 - 8800*p.getValuef());
886 } else if (p == yr) {
887 y.setDuration(10000 - 9000*p.getValuef());
888 } else if (p == zr) {
889 z.setDuration(10000 - 9000*p.getValuef());
895 protected void updateXYZVals() {
901 public void run(double deltaMs) {
904 float xlv = 100*xl.getValuef();
905 float ylv = 100*yl.getValuef();
906 float zlv = 100*zl.getValuef();
908 float xwv = 100. / (10 + 40*xw.getValuef());
909 float ywv = 100. / (10 + 40*yw.getValuef());
910 float zwv = 100. / (10 + 40*zw.getValuef());
912 for (Point p : model.points) {
914 c = blendColor(c, lx.hsb(
915 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
916 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
917 max(0, xlv - xwv*abs(p.x - xv))
919 c = blendColor(c, lx.hsb(
920 (lx.getBaseHuef() + 80 + p.y/10) % 360,
921 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
922 max(0, ylv - ywv*abs(p.y - yv))
924 c = blendColor(c, lx.hsb(
925 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
926 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
927 max(0, zlv - zwv*abs(p.z - zv))
934 class Blinders extends SCPattern {
939 final TriangleLFO hs;
941 public Blinders(GLucose glucose) {
944 for (int i = 0; i < m.length; ++i) {
945 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
947 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
948 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
949 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
950 s.modulateDurationBy(r);
953 public void run(double deltaMs) {
954 float hv = lx.getBaseHuef();
956 for (Strip strip : model.strips) {
958 float mv = m[si % m.length].getValuef();
959 for (Point p : strip.points) {
960 colors[p.index] = lx.hsb(
961 (hv + p.z + p.y*hs.getValuef()) % 360,
962 min(100, abs(p.x - s.getValuef())/2.),
963 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
972 class Psychedelia extends SCPattern {
975 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
976 SinLFO s = new SinLFO(-20, 147, 11000);
977 TriangleLFO h = new TriangleLFO(0, 240, 19000);
978 SinLFO c = new SinLFO(-.2, .8, 31000);
980 Psychedelia(GLucose glucose) {
982 addModulator(m).trigger();
983 addModulator(s).trigger();
984 addModulator(h).trigger();
985 addModulator(c).trigger();
988 void run(double deltaMs) {
989 float huev = h.getValuef();
990 float cv = c.getValuef();
991 float sv = s.getValuef();
992 float mv = m.getValuef();
994 for (Strip strip : model.strips) {
995 for (Point p : strip.points) {
996 colors[p.index] = lx.hsb(
997 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
998 min(100, abs(p.y-sv)),
999 max(0, 100 - 50*abs((i%NUM) - mv))
1007 class AskewPlanes extends SCPattern {
1010 private final SinLFO a;
1011 private final SinLFO b;
1012 private final SinLFO c;
1019 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1020 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1021 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1024 void run(double deltaMs) {
1028 denom = sqrt(av*av + bv*bv);
1032 final Plane[] planes;
1033 final int NUM_PLANES = 3;
1035 AskewPlanes(GLucose glucose) {
1037 planes = new Plane[NUM_PLANES];
1038 for (int i = 0; i < planes.length; ++i) {
1039 planes[i] = new Plane(i);
1043 public void run(double deltaMs) {
1044 float huev = lx.getBaseHuef();
1046 // This is super fucking bizarre. But if this is a for loop, the framerate
1047 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1048 // Doesn't make ANY sense... there must be some weird side effect going on
1049 // with the Processing internals perhaps?
1050 // for (Plane plane : planes) {
1051 // plane.run(deltaMs);
1053 planes[0].run(deltaMs);
1054 planes[1].run(deltaMs);
1055 planes[2].run(deltaMs);
1057 for (Point p : model.points) {
1058 float d = MAX_FLOAT;
1059 for (Plane plane : planes) {
1060 if (plane.denom != 0) {
1061 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1064 colors[p.index] = lx.hsb(
1065 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1066 max(0, 100 - .8*abs(p.x - model.cx)),
1067 constrain(140 - 10.*d, 0, 100)
1073 class ShiftingPlane extends SCPattern {
1075 final SinLFO a = new SinLFO(-.2, .2, 5300);
1076 final SinLFO b = new SinLFO(1, -1, 13300);
1077 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1078 final SinLFO d = new SinLFO(-10, 10, 9500);
1080 ShiftingPlane(GLucose glucose) {
1082 addModulator(a).trigger();
1083 addModulator(b).trigger();
1084 addModulator(c).trigger();
1085 addModulator(d).trigger();
1088 public void run(double deltaMs) {
1089 float hv = lx.getBaseHuef();
1090 float av = a.getValuef();
1091 float bv = b.getValuef();
1092 float cv = c.getValuef();
1093 float dv = d.getValuef();
1094 float denom = sqrt(av*av + bv*bv + cv*cv);
1095 for (Point p : model.points) {
1096 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1097 colors[p.index] = lx.hsb(
1098 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1099 constrain(110 - d*6, 0, 100),
1100 constrain(130 - 7*d, 0, 100)
1106 class Traktor extends SCPattern {
1108 final int FRAME_WIDTH = 60;
1110 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1112 private float[] bass = new float[FRAME_WIDTH];
1113 private float[] treble = new float[FRAME_WIDTH];
1115 private int index = 0;
1116 private GraphicEQ eq = null;
1118 public Traktor(GLucose glucose) {
1120 for (int i = 0; i < FRAME_WIDTH; ++i) {
1124 addParameter(speed);
1127 public void onActive() {
1129 eq = new GraphicEQ(lx, 16);
1130 eq.slope.setValue(0.6);
1131 eq.level.setValue(0.65);
1132 eq.range.setValue(0.35);
1133 eq.release.setValue(0.4);
1134 addParameter(eq.level);
1135 addParameter(eq.range);
1136 addParameter(eq.attack);
1137 addParameter(eq.release);
1138 addParameter(eq.slope);
1144 public void run(double deltaMs) {
1147 int stepThresh = (int) (40 - 39*speed.getValuef());
1149 if (counter < stepThresh) {
1152 counter = counter % stepThresh;
1154 index = (index + 1) % FRAME_WIDTH;
1156 float rawBass = eq.getAverageLevel(0, 4);
1157 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1159 bass[index] = rawBass * rawBass * rawBass * rawBass;
1160 treble[index] = rawTreble * rawTreble;
1162 for (Point p : model.points) {
1163 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1164 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1166 colors[p.index] = lx.hsb(
1167 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1169 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100)
1171 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1172 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1174 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1181 class ColorFuckerEffect extends SCEffect {
1183 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1184 BasicParameter sat = new BasicParameter("SAT", 1);
1185 BasicParameter bright = new BasicParameter("BRT", 1);
1186 float[] hsb = new float[3];
1188 ColorFuckerEffect(GLucose glucose) {
1190 addParameter(hueShift);
1191 addParameter(bright);
1195 public void doApply(int[] colors) {
1199 float bMod = bright.getValuef();
1200 float sMod = sat.getValuef();
1201 float hMod = hueShift.getValuef();
1202 if (bMod < 1 || sMod < 1 || hMod > 0) {
1203 for (int i = 0; i < colors.length; ++i) {
1204 lx.RGBtoHSB(colors[i], hsb);
1206 (360. * hsb[0] + hueShift.getValuef()*360.) % 360,
1207 100. * hsb[1] * sat.getValuef(),
1208 100. * hsb[2] * bright.getValuef()
1215 class BlurEffect extends SCEffect {
1217 final LXParameter amount = new BasicParameter("AMT", 0);
1219 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1221 BlurEffect(GLucose glucose) {
1223 addParameter(amount);
1225 frame = new int[lx.total];
1226 for (int i = 0; i < frame.length; ++i) {
1231 public void onEnable() {
1232 env.setRangeFromHereTo(1, 400).start();
1233 for (int i = 0; i < frame.length; ++i) {
1238 public void onDisable() {
1239 env.setRangeFromHereTo(0, 1000).start();
1242 public void doApply(int[] colors) {
1243 float amt = env.getValuef() * amount.getValuef();
1246 amt = 1 - (amt*amt*amt);
1247 for (int i = 0; i < colors.length; ++i) {
1248 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1249 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);