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(int 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(int 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, (int) (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 class BassPod extends SCPattern {
133 private GraphicEQ eq = null;
135 public BassPod(GLucose glucose) {
139 protected void onActive() {
141 eq = new GraphicEQ(lx, 16);
142 eq.slope.setValue(0.6);
143 addParameter(eq.level);
144 addParameter(eq.range);
145 addParameter(eq.attack);
146 addParameter(eq.release);
147 addParameter(eq.slope);
151 public void run(int deltaMs) {
154 float bassLevel = eq.getAverageLevel(0, 5);
156 for (Point p : model.points) {
157 int avgIndex = (int) constrain(1 + abs(p.fx-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
159 for (int i = avgIndex; i < avgIndex + 5; ++i) {
160 value += eq.getLevel(i);
164 float b = constrain(8 * (value*model.yMax - abs(p.fy-model.yMax/2.)), 0, 100);
165 colors[p.index] = color(
166 (lx.getBaseHuef() + abs(p.fy - model.cy) + abs(p.fx - model.cx)) % 360,
167 constrain(bassLevel*240 - .6*dist(p.fx, p.fy, model.cx, model.cy), 0, 100),
175 class CubeEQ extends SCPattern {
177 private GraphicEQ eq = null;
179 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
180 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
181 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
183 public CubeEQ(GLucose glucose) {
187 protected void onActive() {
189 eq = new GraphicEQ(lx, 16);
190 addParameter(eq.level);
191 addParameter(eq.range);
192 addParameter(eq.attack);
193 addParameter(eq.release);
194 addParameter(eq.slope);
197 addParameter(blockiness);
201 public void run(int deltaMs) {
204 float edgeConst = 2 + 30*edge.getValuef();
205 float clrConst = 1.1 + clr.getValuef();
207 for (Point p : model.points) {
208 float avgIndex = constrain(2 + p.fx / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
209 int avgFloor = (int) avgIndex;
211 float leftVal = eq.getLevel(avgFloor);
212 float rightVal = eq.getLevel(avgFloor+1);
213 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
215 float chunkyValue = (
216 eq.getLevel(avgFloor/4*4) +
217 eq.getLevel(avgFloor/4*4 + 1) +
218 eq.getLevel(avgFloor/4*4 + 2) +
219 eq.getLevel(avgFloor/4*4 + 3)
222 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
224 float b = constrain(edgeConst * (value*model.yMax - p.fy), 0, 100);
225 colors[p.index] = color(
226 (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360,
234 class BoomEffect extends SCEffect {
236 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
237 final BasicParameter speed = new BasicParameter("SPD", 0.5);
238 final BasicParameter bright = new BasicParameter("BRT", 1.0);
239 final BasicParameter sat = new BasicParameter("SAT", 0.2);
240 List<Layer> layers = new ArrayList<Layer>();
241 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
244 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
252 float falloffv = falloffv();
253 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
257 void doApply(int[] colors) {
258 float brightv = 100 * bright.getValuef();
259 float falloffv = falloffv();
260 float satv = sat.getValuef() * 100;
261 float huev = lx.getBaseHuef();
262 for (Point p : model.points) {
263 colors[p.index] = blendColor(
265 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)),
271 BoomEffect(GLucose glucose) {
272 super(glucose, true);
273 addParameter(falloff);
275 addParameter(bright);
279 public void onEnable() {
280 for (Layer l : layers) {
281 if (!l.boom.isRunning()) {
286 layers.add(new Layer());
289 private float falloffv() {
290 return 20 - 19 * falloff.getValuef();
293 public void onTrigger() {
297 public void doApply(int[] colors) {
298 for (Layer l : layers) {
299 if (l.boom.isRunning()) {
306 public class PianoKeyPattern extends SCPattern {
308 final LinearEnvelope[] cubeBrt;
310 final BasicParameter attack = new BasicParameter("ATK", 0.1);
311 final BasicParameter release = new BasicParameter("REL", 0.5);
312 final BasicParameter level = new BasicParameter("AMB", 0.6);
314 PianoKeyPattern(GLucose glucose) {
317 for (MidiInputDevice input : RWMidi.getInputDevices()) {
318 input.createInput(this);
321 addParameter(attack);
322 addParameter(release);
324 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
325 for (int i = 0; i < cubeBrt.length; ++i) {
326 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
328 base = new SinLFO[model.cubes.size() / 12];
329 for (int i = 0; i < base.length; ++i) {
330 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
334 private float getAttackTime() {
335 return 15 + attack.getValuef()*attack.getValuef() * 2000;
338 private float getReleaseTime() {
339 return 15 + release.getValuef() * 3000;
342 private LinearEnvelope getEnvelope(int index) {
343 return cubeBrt[index % cubeBrt.length];
346 private SinLFO getBase(int index) {
347 return base[index % base.length];
350 public void noteOnReceived(Note note) {
351 LinearEnvelope env = getEnvelope(note.getPitch());
352 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
355 public void noteOffReceived(Note note) {
356 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
359 public void run(int deltaMs) {
361 float huef = lx.getBaseHuef();
362 float levelf = level.getValuef();
363 for (Cube c : model.cubes) {
364 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
366 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
374 class CrossSections extends SCPattern {
376 final SinLFO x = new SinLFO(0, model.xMax, 5000);
377 final SinLFO y = new SinLFO(0, model.yMax, 6000);
378 final SinLFO z = new SinLFO(0, model.zMax, 7000);
380 final BasicParameter xw = new BasicParameter("XWID", 0.3);
381 final BasicParameter yw = new BasicParameter("YWID", 0.3);
382 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
383 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
384 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
385 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
386 final BasicParameter xl = new BasicParameter("XLEV", 1);
387 final BasicParameter yl = new BasicParameter("YLEV", 1);
388 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
391 CrossSections(GLucose glucose) {
393 addModulator(x).trigger();
394 addModulator(y).trigger();
395 addModulator(z).trigger();
399 protected void addParams() {
411 void onParameterChanged(LXParameter p) {
413 x.setDuration(10000 - 8800*p.getValuef());
414 } else if (p == yr) {
415 y.setDuration(10000 - 9000*p.getValuef());
416 } else if (p == zr) {
417 z.setDuration(10000 - 9000*p.getValuef());
423 protected void updateXYZVals() {
429 public void run(int deltaMs) {
432 float xlv = 100*xl.getValuef();
433 float ylv = 100*yl.getValuef();
434 float zlv = 100*zl.getValuef();
436 float xwv = 100. / (10 + 40*xw.getValuef());
437 float ywv = 100. / (10 + 40*yw.getValuef());
438 float zwv = 100. / (10 + 40*zw.getValuef());
440 for (Point p : model.points) {
442 c = blendColor(c, color(
443 (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360,
444 constrain(140 - 1.1*abs(p.fx - model.xMax/2.), 0, 100),
445 max(0, xlv - xwv*abs(p.fx - xv))
447 c = blendColor(c, color(
448 (lx.getBaseHuef() + 80 + p.fy/10) % 360,
449 constrain(140 - 2.2*abs(p.fy - model.yMax/2.), 0, 100),
450 max(0, ylv - ywv*abs(p.fy - yv))
452 c = blendColor(c, color(
453 (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360,
454 constrain(140 - 2.2*abs(p.fz - model.zMax/2.), 0, 100),
455 max(0, zlv - zwv*abs(p.fz - zv))
462 class Blinders extends SCPattern {
467 final TriangleLFO hs;
469 public Blinders(GLucose glucose) {
472 for (int i = 0; i < m.length; ++i) {
473 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
475 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
476 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
477 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
478 s.modulateDurationBy(r);
481 public void run(int deltaMs) {
482 float hv = lx.getBaseHuef();
484 for (Strip strip : model.strips) {
486 float mv = m[si % m.length].getValuef();
487 for (Point p : strip.points) {
488 colors[p.index] = color(
489 (hv + p.fz + p.fy*hs.getValuef()) % 360,
490 min(100, abs(p.fx - s.getValuef())/2.),
491 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
500 class Psychedelia extends SCPattern {
503 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
504 SinLFO s = new SinLFO(-20, 147, 11000);
505 TriangleLFO h = new TriangleLFO(0, 240, 19000);
506 SinLFO c = new SinLFO(-.2, .8, 31000);
508 Psychedelia(GLucose glucose) {
510 addModulator(m).trigger();
511 addModulator(s).trigger();
512 addModulator(h).trigger();
513 addModulator(c).trigger();
516 void run(int deltaMs) {
517 float huev = h.getValuef();
518 float cv = c.getValuef();
519 float sv = s.getValuef();
520 float mv = m.getValuef();
522 for (Strip strip : model.strips) {
523 for (Point p : strip.points) {
524 colors[p.index] = color(
525 (huev + i*constrain(cv, 0, 2) + p.fz/2. + p.fx/4.) % 360,
526 min(100, abs(p.fy-sv)),
527 max(0, 100 - 50*abs((i%NUM) - mv))
535 class AskewPlanes extends SCPattern {
538 private final SinLFO a;
539 private final SinLFO b;
540 private final SinLFO c;
547 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
548 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
549 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
552 void run(int deltaMs) {
556 denom = sqrt(av*av + bv*bv);
560 final Plane[] planes;
561 final int NUM_PLANES = 3;
563 AskewPlanes(GLucose glucose) {
565 planes = new Plane[NUM_PLANES];
566 for (int i = 0; i < planes.length; ++i) {
567 planes[i] = new Plane(i);
571 public void run(int deltaMs) {
572 float huev = lx.getBaseHuef();
574 // This is super fucking bizarre. But if this is a for loop, the framerate
575 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
576 // Doesn't make ANY sense... there must be some weird side effect going on
577 // with the Processing internals perhaps?
578 // for (Plane plane : planes) {
579 // plane.run(deltaMs);
581 planes[0].run(deltaMs);
582 planes[1].run(deltaMs);
583 planes[2].run(deltaMs);
585 for (Point p : model.points) {
587 for (Plane plane : planes) {
588 if (plane.denom != 0) {
589 d = min(d, abs(plane.av*(p.fx-model.cx) + plane.bv*(p.fy-model.cy) + plane.cv) / plane.denom);
592 colors[p.index] = color(
593 (huev + abs(p.fx-model.cx)*.3 + p.fy*.8) % 360,
594 max(0, 100 - .8*abs(p.fx - model.cx)),
595 constrain(140 - 10.*d, 0, 100)
601 class ShiftingPlane extends SCPattern {
603 final SinLFO a = new SinLFO(-.2, .2, 5300);
604 final SinLFO b = new SinLFO(1, -1, 13300);
605 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
606 final SinLFO d = new SinLFO(-10, 10, 9500);
608 ShiftingPlane(GLucose glucose) {
610 addModulator(a).trigger();
611 addModulator(b).trigger();
612 addModulator(c).trigger();
613 addModulator(d).trigger();
616 public void run(int deltaMs) {
617 float hv = lx.getBaseHuef();
618 float av = a.getValuef();
619 float bv = b.getValuef();
620 float cv = c.getValuef();
621 float dv = d.getValuef();
622 float denom = sqrt(av*av + bv*bv + cv*cv);
623 for (Point p : model.points) {
624 float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom;
625 colors[p.index] = color(
626 (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360,
627 constrain(110 - d*6, 0, 100),
628 constrain(130 - 7*d, 0, 100)
634 class Traktor extends SCPattern {
636 final int FRAME_WIDTH = 60;
638 final BasicParameter speed = new BasicParameter("SPD", 0.5);
640 private float[] bass = new float[FRAME_WIDTH];
641 private float[] treble = new float[FRAME_WIDTH];
643 private int index = 0;
644 private GraphicEQ eq = null;
646 public Traktor(GLucose glucose) {
648 for (int i = 0; i < FRAME_WIDTH; ++i) {
655 public void onActive() {
657 eq = new GraphicEQ(lx, 16);
658 eq.slope.setValue(0.6);
659 eq.level.setValue(0.65);
660 eq.range.setValue(0.35);
661 eq.release.setValue(0.4);
662 addParameter(eq.level);
663 addParameter(eq.range);
664 addParameter(eq.attack);
665 addParameter(eq.release);
666 addParameter(eq.slope);
672 public void run(int deltaMs) {
675 int stepThresh = (int) (40 - 39*speed.getValuef());
677 if (counter < stepThresh) {
680 counter = counter % stepThresh;
682 index = (index + 1) % FRAME_WIDTH;
684 float rawBass = eq.getAverageLevel(0, 4);
685 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
687 bass[index] = rawBass * rawBass * rawBass * rawBass;
688 treble[index] = rawTreble * rawTreble;
690 for (Point p : model.points) {
691 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
692 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
694 colors[p.index] = color(
695 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
697 constrain(9 * (bass[pos]*model.cy - abs(p.fy - model.cy)), 0, 100)
699 colors[p.index] = blendColor(colors[p.index], color(
700 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
702 constrain(5 * (treble[pos]*.6*model.cy - abs(p.fy - model.cy)), 0, 100)
709 class ColorFuckerEffect extends SCEffect {
711 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
712 BasicParameter sat = new BasicParameter("SAT", 1);
713 BasicParameter bright = new BasicParameter("BRT", 1);
715 ColorFuckerEffect(GLucose glucose) {
717 addParameter(hueShift);
718 addParameter(bright);
722 public void doApply(int[] colors) {
723 float bMod = bright.getValuef();
724 float sMod = sat.getValuef();
725 float hMod = hueShift.getValuef();
726 if (bMod < 1 || sMod < 1 || hMod > 0) {
727 for (int i = 0; i < colors.length; ++i) {
729 (hue(colors[i]) + hueShift.getValuef()*360.) % 360,
730 saturation(colors[i]) * sat.getValuef(),
731 brightness(colors[i]) * bright.getValuef()