+
+class AskewPlanes extends SCPattern {
+
+ class Plane {
+ private final SinLFO a;
+ private final SinLFO b;
+ private final SinLFO c;
+ float av = 1;
+ float bv = 1;
+ float cv = 1;
+ float denom = 0.1;
+
+ Plane(int i) {
+ addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
+ addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
+ addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
+ }
+
+ void run(double deltaMs) {
+ av = a.getValuef();
+ bv = b.getValuef();
+ cv = c.getValuef();
+ denom = sqrt(av*av + bv*bv);
+ }
+ }
+
+ final Plane[] planes;
+ final int NUM_PLANES = 3;
+
+ AskewPlanes(GLucose glucose) {
+ super(glucose);
+ planes = new Plane[NUM_PLANES];
+ for (int i = 0; i < planes.length; ++i) {
+ planes[i] = new Plane(i);
+ }
+ }
+
+ public void run(double deltaMs) {
+ float huev = lx.getBaseHuef();
+
+ // This is super fucking bizarre. But if this is a for loop, the framerate
+ // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
+ // Doesn't make ANY sense... there must be some weird side effect going on
+ // with the Processing internals perhaps?
+// for (Plane plane : planes) {
+// plane.run(deltaMs);
+// }
+ planes[0].run(deltaMs);
+ planes[1].run(deltaMs);
+ planes[2].run(deltaMs);
+
+ for (Point p : model.points) {
+ float d = MAX_FLOAT;
+ for (Plane plane : planes) {
+ if (plane.denom != 0) {
+ d = min(d, abs(plane.av*(p.fx-model.cx) + plane.bv*(p.fy-model.cy) + plane.cv) / plane.denom);
+ }
+ }
+ colors[p.index] = color(
+ (huev + abs(p.fx-model.cx)*.3 + p.fy*.8) % 360,
+ max(0, 100 - .8*abs(p.fx - model.cx)),
+ constrain(140 - 10.*d, 0, 100)
+ );
+ }
+ }
+}
+
+class ShiftingPlane extends SCPattern {
+
+ final SinLFO a = new SinLFO(-.2, .2, 5300);
+ final SinLFO b = new SinLFO(1, -1, 13300);
+ final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
+ final SinLFO d = new SinLFO(-10, 10, 9500);
+
+ ShiftingPlane(GLucose glucose) {
+ super(glucose);
+ addModulator(a).trigger();
+ addModulator(b).trigger();
+ addModulator(c).trigger();
+ addModulator(d).trigger();
+ }
+
+ public void run(double deltaMs) {
+ float hv = lx.getBaseHuef();
+ float av = a.getValuef();
+ float bv = b.getValuef();
+ float cv = c.getValuef();
+ float dv = d.getValuef();
+ float denom = sqrt(av*av + bv*bv + cv*cv);
+ for (Point p : model.points) {
+ float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom;
+ colors[p.index] = color(
+ (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360,
+ constrain(110 - d*6, 0, 100),
+ constrain(130 - 7*d, 0, 100)
+ );
+ }
+ }
+}
+
+class Traktor extends SCPattern {
+
+ final int FRAME_WIDTH = 60;
+
+ final BasicParameter speed = new BasicParameter("SPD", 0.5);
+
+ private float[] bass = new float[FRAME_WIDTH];
+ private float[] treble = new float[FRAME_WIDTH];
+
+ private int index = 0;
+ private GraphicEQ eq = null;
+
+ public Traktor(GLucose glucose) {
+ super(glucose);
+ for (int i = 0; i < FRAME_WIDTH; ++i) {
+ bass[i] = 0;
+ treble[i] = 0;
+ }
+ addParameter(speed);
+ }
+
+ public void onActive() {
+ if (eq == null) {
+ eq = new GraphicEQ(lx, 16);
+ eq.slope.setValue(0.6);
+ eq.level.setValue(0.65);
+ eq.range.setValue(0.35);
+ eq.release.setValue(0.4);
+ addParameter(eq.level);
+ addParameter(eq.range);
+ addParameter(eq.attack);
+ addParameter(eq.release);
+ addParameter(eq.slope);
+ }
+ }
+
+ int counter = 0;
+
+ public void run(double deltaMs) {
+ eq.run(deltaMs);
+
+ int stepThresh = (int) (40 - 39*speed.getValuef());
+ counter += deltaMs;
+ if (counter < stepThresh) {
+ return;
+ }
+ counter = counter % stepThresh;
+
+ index = (index + 1) % FRAME_WIDTH;
+
+ float rawBass = eq.getAverageLevel(0, 4);
+ float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
+
+ bass[index] = rawBass * rawBass * rawBass * rawBass;
+ treble[index] = rawTreble * rawTreble;
+
+ for (Point p : model.points) {
+ int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
+ int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
+
+ colors[p.index] = color(
+ (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
+ 100,
+ constrain(9 * (bass[pos]*model.cy - abs(p.fy - model.cy)), 0, 100)
+ );
+ colors[p.index] = blendColor(colors[p.index], color(
+ (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
+ 60,
+ constrain(5 * (treble[pos]*.6*model.cy - abs(p.fy - model.cy)), 0, 100)
+
+ ), ADD);
+ }
+ }
+}
+
+class ColorFuckerEffect extends SCEffect {
+
+ BasicParameter hueShift = new BasicParameter("HSHFT", 0);
+ BasicParameter sat = new BasicParameter("SAT", 1);
+ BasicParameter bright = new BasicParameter("BRT", 1);
+
+ ColorFuckerEffect(GLucose glucose) {
+ super(glucose);
+ addParameter(hueShift);
+ addParameter(bright);
+ addParameter(sat);
+ }
+
+ public void doApply(int[] colors) {
+ if (!enabled) {
+ return;
+ }
+ float bMod = bright.getValuef();
+ float sMod = sat.getValuef();
+ float hMod = hueShift.getValuef();
+ if (bMod < 1 || sMod < 1 || hMod > 0) {
+ for (int i = 0; i < colors.length; ++i) {
+ colors[i] = color(
+ (hue(colors[i]) + hueShift.getValuef()*360.) % 360,
+ saturation(colors[i]) * sat.getValuef(),
+ brightness(colors[i]) * bright.getValuef()
+ );
+ }
+ }
+ }
+}
+
+class BlurEffect extends SCEffect {
+
+ final LXParameter amount = new BasicParameter("AMT", 0);
+ final int[] frame;
+ final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
+
+ BlurEffect(GLucose glucose) {
+ super(glucose);
+ addParameter(amount);
+ addModulator(env);
+ frame = new int[lx.total];
+ for (int i = 0; i < frame.length; ++i) {
+ frame[i] = #000000;
+ }
+ }
+
+ public void onEnable() {
+ env.setRangeFromHereTo(1, 400).start();
+ for (int i = 0; i < frame.length; ++i) {
+ frame[i] = #000000;
+ }
+ }
+
+ public void onDisable() {
+ env.setRangeFromHereTo(0, 1000).start();
+ }
+
+ public void doApply(int[] colors) {
+ float amt = env.getValuef() * amount.getValuef();
+ if (amt > 0) {
+ amt = (1 - amt);
+ amt = 1 - (amt*amt*amt);
+ for (int i = 0; i < colors.length; ++i) {
+ // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
+ frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);
+ }
+ }
+
+ }
+}