dpat fixes
[SugarCubes.git] / MarkSlee.pde
CommitLineData
d1dcc4b5 1class BouncyBalls extends SCPattern {
cc8b3f82 2
d1dcc4b5 3 static final int NUM_BALLS = 6;
cc8b3f82 4
d1dcc4b5 5 class BouncyBall {
cc8b3f82
MS
6
7 Accelerator yPos;
8 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
d1dcc4b5 9 float zPos;
cc8b3f82 10
d1dcc4b5 11 BouncyBall(int i) {
cc8b3f82
MS
12 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
13 addModulator(yPos = new Accelerator(0, 0, 0));
d1dcc4b5 14 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
cc8b3f82
MS
15 }
16
17 void bounce(float midiVel) {
18 float v = 100 + 8*midiVel;
19 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
20 }
21
22 float getAccel(float v, float oneBeat) {
23 return -2*v / oneBeat;
24 }
25
26 void run(double deltaMs) {
27 float flrLevel = flr.getValuef() * model.xMax/2.;
28 if (yPos.getValuef() < flrLevel) {
29 if (yPos.getVelocity() < -50) {
30 yPos.setValue(2*flrLevel-yPos.getValuef());
31 float v = -yPos.getVelocityf() * bounce.getValuef();
32 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
33 } else {
34 yPos.setValue(flrLevel).stop();
35 }
36 }
37 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
d1dcc4b5
MS
38 float xv = xPos.getValuef();
39 float yv = yPos.getValuef();
40
cc8b3f82 41 for (Point p : model.points) {
d1dcc4b5 42 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
cc8b3f82
MS
43 float b = constrain(130 - falloff*d, 0, 100);
44 if (b > 0) {
45 colors[p.index] = blendColor(colors[p.index], color(
46 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
47 max(0, 100 - .45*(p.y - flrLevel)),
48 b
49 ), ADD);
50 }
51 }
52 }
53 }
54
d1dcc4b5 55 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
cc8b3f82
MS
56
57 final BasicParameter bounce = new BasicParameter("BNC", .8);
58 final BasicParameter flr = new BasicParameter("FLR", 0);
59 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
60
d1dcc4b5 61 BouncyBalls(GLucose glucose) {
cc8b3f82 62 super(glucose);
d1dcc4b5
MS
63 for (int i = 0; i < balls.length; ++i) {
64 balls[i] = new BouncyBall(i);
cc8b3f82
MS
65 }
66 addParameter(bounce);
67 addParameter(flr);
68 addParameter(blobSize);
69 }
70
71 public void run(double deltaMs) {
72 setColors(#000000);
d1dcc4b5
MS
73 for (BouncyBall b : balls) {
74 b.run(deltaMs);
cc8b3f82
MS
75 }
76 }
77
78 public boolean noteOnReceived(Note note) {
d1dcc4b5
MS
79 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
80 balls[pitch].bounce(note.getVelocity());
cc8b3f82
MS
81 return true;
82 }
83}
84
49815cc0
MS
85class SpaceTime extends SCPattern {
86
3e8e60d8 87 SinLFO pos = new SinLFO(0, 1, 3000);
49815cc0
MS
88 SinLFO rate = new SinLFO(1000, 9000, 13000);
89 SinLFO falloff = new SinLFO(10, 70, 5000);
3f8be614
MS
90 float angle = 0;
91
92 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
93 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
49815cc0 94
3e8e60d8 95
49815cc0
MS
96 public SpaceTime(GLucose glucose) {
97 super(glucose);
3e8e60d8 98
49815cc0
MS
99 addModulator(pos).trigger();
100 addModulator(rate).trigger();
101 addModulator(falloff).trigger();
102 pos.modulateDurationBy(rate);
3f8be614
MS
103 addParameter(rateParameter);
104 addParameter(sizeParameter);
49815cc0 105 }
3f8be614
MS
106
107 public void onParameterChanged(LXParameter parameter) {
108 if (parameter == rateParameter) {
109 rate.stop().setValue(9000 - 8000*parameter.getValuef());
110 } else if (parameter == sizeParameter) {
111 falloff.stop().setValue(70 - 60*parameter.getValuef());
49815cc0
MS
112 }
113 }
114
34327c96 115 void run(double deltaMs) {
3f8be614 116 angle += deltaMs * 0.0007;
87f6fa39
MS
117 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
118 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
49815cc0
MS
119
120 float pVal = pos.getValuef();
121 float fVal = falloff.getValuef();
122
123 int s = 0;
cfc57fca 124 for (Strip strip : model.strips) {
49815cc0
MS
125 int i = 0;
126 for (Point p : strip.points) {
127 colors[p.index] = color(
3e8e60d8
MS
128 (lx.getBaseHuef() + 360 - p.fx*.2 + p.fy * .3) % 360,
129 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
130 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
131 );
49815cc0
MS
132 ++i;
133 }
3f8be614 134 ++s;
49815cc0
MS
135 }
136 }
137}
138
139class Swarm extends SCPattern {
140
3e8e60d8 141 SawLFO offset = new SawLFO(0, 1, 1000);
49815cc0
MS
142 SinLFO rate = new SinLFO(350, 1200, 63000);
143 SinLFO falloff = new SinLFO(15, 50, 17000);
c39f7a04
MS
144 SinLFO fX = new SinLFO(0, model.xMax, 19000);
145 SinLFO fY = new SinLFO(0, model.yMax, 11000);
146 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
49815cc0
MS
147
148 public Swarm(GLucose glucose) {
149 super(glucose);
3e8e60d8 150
49815cc0
MS
151 addModulator(offset).trigger();
152 addModulator(rate).trigger();
153 addModulator(falloff).trigger();
2b6688e8 154 addModulator(fX).trigger();
49815cc0 155 addModulator(fY).trigger();
2b6688e8 156 addModulator(hOffX).trigger();
49815cc0
MS
157 offset.modulateDurationBy(rate);
158 }
159
160 float modDist(float v1, float v2, float mod) {
161 v1 = v1 % mod;
162 v2 = v2 % mod;
163 if (v2 > v1) {
164 return min(v2-v1, v1+mod-v2);
165 }
166 else {
167 return min(v1-v2, v2+mod-v1);
168 }
169 }
170
34327c96 171 void run(double deltaMs) {
49815cc0 172 float s = 0;
cfc57fca 173 for (Strip strip : model.strips ) {
49815cc0
MS
174 int i = 0;
175 for (Point p : strip.points) {
2b6688e8 176 float fV = max(-1, 1 - dist(p.fx/2., p.fy, fX.getValuef()/2., fY.getValuef()) / 64.);
49815cc0 177 colors[p.index] = color(
2b6688e8 178 (lx.getBaseHuef() + 0.3 * abs(p.fx - hOffX.getValuef())) % 360,
49815cc0 179 constrain(80 + 40 * fV, 0, 100),
34327c96 180 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
49815cc0
MS
181 );
182 ++i;
183 }
184 ++s;
185 }
186 }
187}
188
189class SwipeTransition extends SCTransition {
3f8be614
MS
190
191 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
192
49815cc0
MS
193 SwipeTransition(GLucose glucose) {
194 super(glucose);
195 setDuration(5000);
3f8be614 196 addParameter(bleed);
49815cc0
MS
197 }
198
199 void computeBlend(int[] c1, int[] c2, double progress) {
3f8be614 200 float bleedf = 10 + bleed.getValuef() * 200.;
c39f7a04 201 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
87f6fa39 202 for (Point p : model.points) {
2b6688e8 203 float d = (p.fx - xPos) / bleedf;
49815cc0
MS
204 if (d < 0) {
205 colors[p.index] = c2[p.index];
2b6688e8 206 } else if (d > 1) {
49815cc0 207 colors[p.index] = c1[p.index];
2b6688e8 208 } else {
49815cc0
MS
209 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
210 }
211 }
212 }
213}
214
fe30b226 215abstract class BlendTransition extends SCTransition {
ed149627 216
fe30b226
MS
217 final int blendType;
218
219 BlendTransition(GLucose glucose, int blendType) {
ed149627 220 super(glucose);
fe30b226 221 this.blendType = blendType;
ed149627
MS
222 }
223
224 void computeBlend(int[] c1, int[] c2, double progress) {
225 if (progress < 0.5) {
226 for (int i = 0; i < c1.length; ++i) {
227 colors[i] = lerpColor(
228 c1[i],
fe30b226 229 blendColor(c1[i], c2[i], blendType),
ed149627
MS
230 (float) (2.*progress),
231 RGB);
232 }
233 } else {
234 for (int i = 0; i < c1.length; ++i) {
235 colors[i] = lerpColor(
236 c2[i],
fe30b226 237 blendColor(c1[i], c2[i], blendType),
ed149627
MS
238 (float) (2.*(1. - progress)),
239 RGB);
240 }
241 }
242 }
243}
244
fe30b226
MS
245class MultiplyTransition extends BlendTransition {
246 MultiplyTransition(GLucose glucose) {
247 super(glucose, MULTIPLY);
248 }
249}
250
251class ScreenTransition extends BlendTransition {
252 ScreenTransition(GLucose glucose) {
253 super(glucose, SCREEN);
254 }
255}
256
257class BurnTransition extends BlendTransition {
258 BurnTransition(GLucose glucose) {
259 super(glucose, BURN);
260 }
261}
262
263class DodgeTransition extends BlendTransition {
264 DodgeTransition(GLucose glucose) {
265 super(glucose, DODGE);
266 }
267}
268
269class OverlayTransition extends BlendTransition {
270 OverlayTransition(GLucose glucose) {
271 super(glucose, OVERLAY);
272 }
273}
274
275class AddTransition extends BlendTransition {
276 AddTransition(GLucose glucose) {
277 super(glucose, ADD);
278 }
279}
280
281class SubtractTransition extends BlendTransition {
282 SubtractTransition(GLucose glucose) {
283 super(glucose, SUBTRACT);
284 }
285}
286
287class SoftLightTransition extends BlendTransition {
288 SoftLightTransition(GLucose glucose) {
289 super(glucose, SOFT_LIGHT);
290 }
291}
ed149627 292
4c006f7b
MS
293class BassPod extends SCPattern {
294
295 private GraphicEQ eq = null;
296
297 public BassPod(GLucose glucose) {
298 super(glucose);
299 }
300
301 protected void onActive() {
302 if (eq == null) {
303 eq = new GraphicEQ(lx, 16);
304 eq.slope.setValue(0.6);
305 addParameter(eq.level);
306 addParameter(eq.range);
307 addParameter(eq.attack);
308 addParameter(eq.release);
309 addParameter(eq.slope);
310 }
311 }
312
34327c96 313 public void run(double deltaMs) {
4c006f7b
MS
314 eq.run(deltaMs);
315
316 float bassLevel = eq.getAverageLevel(0, 5);
317
318 for (Point p : model.points) {
319 int avgIndex = (int) constrain(1 + abs(p.fx-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
320 float value = 0;
321 for (int i = avgIndex; i < avgIndex + 5; ++i) {
322 value += eq.getLevel(i);
323 }
324 value /= 5.;
325
326 float b = constrain(8 * (value*model.yMax - abs(p.fy-model.yMax/2.)), 0, 100);
327 colors[p.index] = color(
328 (lx.getBaseHuef() + abs(p.fy - model.cy) + abs(p.fx - model.cx)) % 360,
329 constrain(bassLevel*240 - .6*dist(p.fx, p.fy, model.cx, model.cy), 0, 100),
330 b
331 );
332 }
333 }
334}
335
336
49815cc0
MS
337class CubeEQ extends SCPattern {
338
4c006f7b 339 private GraphicEQ eq = null;
49815cc0 340
3f8be614 341 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
3f8be614 342 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
4c006f7b 343 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
49815cc0
MS
344
345 public CubeEQ(GLucose glucose) {
346 super(glucose);
49815cc0 347 }
3f8be614 348
49815cc0 349 protected void onActive() {
4c006f7b
MS
350 if (eq == null) {
351 eq = new GraphicEQ(lx, 16);
352 addParameter(eq.level);
353 addParameter(eq.range);
354 addParameter(eq.attack);
355 addParameter(eq.release);
356 addParameter(eq.slope);
357 addParameter(edge);
358 addParameter(clr);
359 addParameter(blockiness);
49815cc0
MS
360 }
361 }
362
34327c96 363 public void run(double deltaMs) {
4c006f7b 364 eq.run(deltaMs);
3f8be614 365
4c006f7b 366 float edgeConst = 2 + 30*edge.getValuef();
49815cc0
MS
367 float clrConst = 1.1 + clr.getValuef();
368
87f6fa39 369 for (Point p : model.points) {
4c006f7b 370 float avgIndex = constrain(2 + p.fx / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
49815cc0 371 int avgFloor = (int) avgIndex;
3f8be614 372
4c006f7b
MS
373 float leftVal = eq.getLevel(avgFloor);
374 float rightVal = eq.getLevel(avgFloor+1);
375 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
376
377 float chunkyValue = (
378 eq.getLevel(avgFloor/4*4) +
379 eq.getLevel(avgFloor/4*4 + 1) +
380 eq.getLevel(avgFloor/4*4 + 2) +
381 eq.getLevel(avgFloor/4*4 + 3)
382 ) / 4.;
383
384 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
385
386 float b = constrain(edgeConst * (value*model.yMax - p.fy), 0, 100);
49815cc0 387 colors[p.index] = color(
4c006f7b
MS
388 (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360,
389 100,
390 b
391 );
3f8be614
MS
392 }
393 }
394}
395
396class BoomEffect extends SCEffect {
397
398 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
399 final BasicParameter speed = new BasicParameter("SPD", 0.5);
400 final BasicParameter bright = new BasicParameter("BRT", 1.0);
401 final BasicParameter sat = new BasicParameter("SAT", 0.2);
402 List<Layer> layers = new ArrayList<Layer>();
c39f7a04 403 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
3f8be614
MS
404
405 class Layer {
406 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
407
408 Layer() {
409 addModulator(boom);
410 trigger();
411 }
412
413 void trigger() {
414 float falloffv = falloffv();
2b6688e8 415 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
3f8be614
MS
416 boom.trigger();
417 }
418
419 void doApply(int[] colors) {
420 float brightv = 100 * bright.getValuef();
421 float falloffv = falloffv();
422 float satv = sat.getValuef() * 100;
423 float huev = lx.getBaseHuef();
87f6fa39 424 for (Point p : model.points) {
3f8be614
MS
425 colors[p.index] = blendColor(
426 colors[p.index],
c39f7a04 427 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)),
3f8be614
MS
428 ADD);
429 }
430 }
431 }
432
433 BoomEffect(GLucose glucose) {
434 super(glucose, true);
435 addParameter(falloff);
436 addParameter(speed);
437 addParameter(bright);
438 addParameter(sat);
439 }
440
441 public void onEnable() {
442 for (Layer l : layers) {
443 if (!l.boom.isRunning()) {
444 l.trigger();
445 return;
446 }
447 }
448 layers.add(new Layer());
449 }
450
451 private float falloffv() {
452 return 20 - 19 * falloff.getValuef();
453 }
454
455 public void onTrigger() {
456 onEnable();
457 }
458
459 public void doApply(int[] colors) {
460 for (Layer l : layers) {
461 if (l.boom.isRunning()) {
462 l.doApply(colors);
463 }
49815cc0
MS
464 }
465 }
466}
467
5d70e4d7
MS
468public class PianoKeyPattern extends SCPattern {
469
470 final LinearEnvelope[] cubeBrt;
471 final SinLFO base[];
472 final BasicParameter attack = new BasicParameter("ATK", 0.1);
473 final BasicParameter release = new BasicParameter("REL", 0.5);
474 final BasicParameter level = new BasicParameter("AMB", 0.6);
475
476 PianoKeyPattern(GLucose glucose) {
477 super(glucose);
a8d55ade 478
5d70e4d7
MS
479 addParameter(attack);
480 addParameter(release);
481 addParameter(level);
87f6fa39 482 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
5d70e4d7
MS
483 for (int i = 0; i < cubeBrt.length; ++i) {
484 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
485 }
87f6fa39 486 base = new SinLFO[model.cubes.size() / 12];
5d70e4d7
MS
487 for (int i = 0; i < base.length; ++i) {
488 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
489 }
490 }
491
492 private float getAttackTime() {
493 return 15 + attack.getValuef()*attack.getValuef() * 2000;
494 }
495
496 private float getReleaseTime() {
497 return 15 + release.getValuef() * 3000;
498 }
499
500 private LinearEnvelope getEnvelope(int index) {
501 return cubeBrt[index % cubeBrt.length];
502 }
503
504 private SinLFO getBase(int index) {
505 return base[index % base.length];
506 }
507
d6ac1ee8 508 public boolean noteOnReceived(Note note) {
5d70e4d7
MS
509 LinearEnvelope env = getEnvelope(note.getPitch());
510 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
d6ac1ee8 511 return true;
5d70e4d7
MS
512 }
513
d6ac1ee8 514 public boolean noteOffReceived(Note note) {
5d70e4d7 515 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
d6ac1ee8 516 return true;
5d70e4d7
MS
517 }
518
34327c96 519 public void run(double deltaMs) {
5d70e4d7
MS
520 int i = 0;
521 float huef = lx.getBaseHuef();
522 float levelf = level.getValuef();
87f6fa39 523 for (Cube c : model.cubes) {
5d70e4d7
MS
524 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
525 setColor(c, color(
e0cea600 526 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
5d70e4d7
MS
527 min(100, 120*v),
528 100*v
529 ));
530 }
531 }
532}
533
0106b29c
MS
534class CrossSections extends SCPattern {
535
c39f7a04
MS
536 final SinLFO x = new SinLFO(0, model.xMax, 5000);
537 final SinLFO y = new SinLFO(0, model.yMax, 6000);
538 final SinLFO z = new SinLFO(0, model.zMax, 7000);
0106b29c
MS
539
540 final BasicParameter xw = new BasicParameter("XWID", 0.3);
541 final BasicParameter yw = new BasicParameter("YWID", 0.3);
542 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
2b6688e8 543 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
0106b29c 544 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
2b6688e8
MS
545 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
546 final BasicParameter xl = new BasicParameter("XLEV", 1);
0106b29c 547 final BasicParameter yl = new BasicParameter("YLEV", 1);
2b6688e8 548 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
0106b29c
MS
549
550
551 CrossSections(GLucose glucose) {
552 super(glucose);
553 addModulator(x).trigger();
554 addModulator(y).trigger();
555 addModulator(z).trigger();
b12bca62
MS
556 addParams();
557 }
558
559 protected void addParams() {
0106b29c
MS
560 addParameter(xr);
561 addParameter(yr);
562 addParameter(zr);
2b6688e8 563 addParameter(xw);
0106b29c
MS
564 addParameter(xl);
565 addParameter(yl);
566 addParameter(zl);
2b6688e8
MS
567 addParameter(yw);
568 addParameter(zw);
0106b29c 569 }
3e8e60d8
MS
570
571 void onParameterChanged(LXParameter p) {
0106b29c 572 if (p == xr) {
2b6688e8 573 x.setDuration(10000 - 8800*p.getValuef());
0106b29c 574 } else if (p == yr) {
2b6688e8 575 y.setDuration(10000 - 9000*p.getValuef());
0106b29c
MS
576 } else if (p == zr) {
577 z.setDuration(10000 - 9000*p.getValuef());
578 }
0106b29c 579 }
b12bca62
MS
580
581 float xv, yv, zv;
582
583 protected void updateXYZVals() {
584 xv = x.getValuef();
585 yv = y.getValuef();
586 zv = z.getValuef();
587 }
0106b29c 588
34327c96 589 public void run(double deltaMs) {
f1c74267
MS
590 updateXYZVals();
591
0106b29c
MS
592 float xlv = 100*xl.getValuef();
593 float ylv = 100*yl.getValuef();
594 float zlv = 100*zl.getValuef();
595
596 float xwv = 100. / (10 + 40*xw.getValuef());
597 float ywv = 100. / (10 + 40*yw.getValuef());
598 float zwv = 100. / (10 + 40*zw.getValuef());
599
87f6fa39 600 for (Point p : model.points) {
0106b29c
MS
601 color c = 0;
602 c = blendColor(c, color(
2b6688e8 603 (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360,
c39f7a04 604 constrain(140 - 1.1*abs(p.fx - model.xMax/2.), 0, 100),
2b6688e8 605 max(0, xlv - xwv*abs(p.fx - xv))
0106b29c
MS
606 ), ADD);
607 c = blendColor(c, color(
2b6688e8 608 (lx.getBaseHuef() + 80 + p.fy/10) % 360,
c39f7a04 609 constrain(140 - 2.2*abs(p.fy - model.yMax/2.), 0, 100),
2b6688e8 610 max(0, ylv - ywv*abs(p.fy - yv))
0106b29c
MS
611 ), ADD);
612 c = blendColor(c, color(
2b6688e8 613 (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360,
c39f7a04 614 constrain(140 - 2.2*abs(p.fz - model.zMax/2.), 0, 100),
2b6688e8 615 max(0, zlv - zwv*abs(p.fz - zv))
0106b29c
MS
616 ), ADD);
617 colors[p.index] = c;
618 }
619 }
620}
621
622class Blinders extends SCPattern {
623
aa54c1ca 624 final SinLFO[] m;
0106b29c
MS
625 final TriangleLFO r;
626 final SinLFO s;
627 final TriangleLFO hs;
628
629 public Blinders(GLucose glucose) {
630 super(glucose);
aa54c1ca
MS
631 m = new SinLFO[12];
632 for (int i = 0; i < m.length; ++i) {
633 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
634 }
635 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
636 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
0106b29c 637 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
aa54c1ca 638 s.modulateDurationBy(r);
0106b29c
MS
639 }
640
34327c96 641 public void run(double deltaMs) {
0106b29c 642 float hv = lx.getBaseHuef();
aa54c1ca 643 int si = 0;
87f6fa39 644 for (Strip strip : model.strips) {
0106b29c 645 int i = 0;
aa54c1ca 646 float mv = m[si % m.length].getValuef();
0106b29c
MS
647 for (Point p : strip.points) {
648 colors[p.index] = color(
2b6688e8
MS
649 (hv + p.fz + p.fy*hs.getValuef()) % 360,
650 min(100, abs(p.fx - s.getValuef())/2.),
254fbb68 651 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
0106b29c
MS
652 );
653 ++i;
654 }
aa54c1ca 655 ++si;
0106b29c
MS
656 }
657 }
658}
659
87f6fa39
MS
660class Psychedelia extends SCPattern {
661
662 final int NUM = 3;
663 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
664 SinLFO s = new SinLFO(-20, 147, 11000);
665 TriangleLFO h = new TriangleLFO(0, 240, 19000);
666 SinLFO c = new SinLFO(-.2, .8, 31000);
667
668 Psychedelia(GLucose glucose) {
669 super(glucose);
670 addModulator(m).trigger();
671 addModulator(s).trigger();
672 addModulator(h).trigger();
673 addModulator(c).trigger();
674 }
0106b29c 675
34327c96 676 void run(double deltaMs) {
87f6fa39
MS
677 float huev = h.getValuef();
678 float cv = c.getValuef();
679 float sv = s.getValuef();
680 float mv = m.getValuef();
681 int i = 0;
682 for (Strip strip : model.strips) {
683 for (Point p : strip.points) {
684 colors[p.index] = color(
685 (huev + i*constrain(cv, 0, 2) + p.fz/2. + p.fx/4.) % 360,
686 min(100, abs(p.fy-sv)),
687 max(0, 100 - 50*abs((i%NUM) - mv))
688 );
689 }
690 ++i;
691 }
692 }
693}
5129affb
MS
694
695class AskewPlanes extends SCPattern {
696
697 class Plane {
698 private final SinLFO a;
699 private final SinLFO b;
700 private final SinLFO c;
775d3394
MS
701 float av = 1;
702 float bv = 1;
703 float cv = 1;
704 float denom = 0.1;
5129affb
MS
705
706 Plane(int i) {
707 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
708 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
709 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
710 }
711
34327c96 712 void run(double deltaMs) {
5129affb
MS
713 av = a.getValuef();
714 bv = b.getValuef();
715 cv = c.getValuef();
716 denom = sqrt(av*av + bv*bv);
717 }
718 }
719
720 final Plane[] planes;
721 final int NUM_PLANES = 3;
722
723 AskewPlanes(GLucose glucose) {
724 super(glucose);
725 planes = new Plane[NUM_PLANES];
726 for (int i = 0; i < planes.length; ++i) {
727 planes[i] = new Plane(i);
728 }
729 }
5129affb 730
34327c96 731 public void run(double deltaMs) {
5129affb 732 float huev = lx.getBaseHuef();
775d3394
MS
733
734 // This is super fucking bizarre. But if this is a for loop, the framerate
735 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
736 // Doesn't make ANY sense... there must be some weird side effect going on
737 // with the Processing internals perhaps?
738// for (Plane plane : planes) {
739// plane.run(deltaMs);
740// }
741 planes[0].run(deltaMs);
742 planes[1].run(deltaMs);
743 planes[2].run(deltaMs);
744
5129affb 745 for (Point p : model.points) {
775d3394
MS
746 float d = MAX_FLOAT;
747 for (Plane plane : planes) {
748 if (plane.denom != 0) {
749 d = min(d, abs(plane.av*(p.fx-model.cx) + plane.bv*(p.fy-model.cy) + plane.cv) / plane.denom);
750 }
751 }
752 colors[p.index] = color(
753 (huev + abs(p.fx-model.cx)*.3 + p.fy*.8) % 360,
754 max(0, 100 - .8*abs(p.fx - model.cx)),
755 constrain(140 - 10.*d, 0, 100)
756 );
5129affb
MS
757 }
758 }
759}
760
761class ShiftingPlane extends SCPattern {
762
763 final SinLFO a = new SinLFO(-.2, .2, 5300);
764 final SinLFO b = new SinLFO(1, -1, 13300);
765 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
766 final SinLFO d = new SinLFO(-10, 10, 9500);
767
768 ShiftingPlane(GLucose glucose) {
769 super(glucose);
770 addModulator(a).trigger();
771 addModulator(b).trigger();
772 addModulator(c).trigger();
773 addModulator(d).trigger();
774 }
775
34327c96 776 public void run(double deltaMs) {
5129affb
MS
777 float hv = lx.getBaseHuef();
778 float av = a.getValuef();
779 float bv = b.getValuef();
780 float cv = c.getValuef();
781 float dv = d.getValuef();
782 float denom = sqrt(av*av + bv*bv + cv*cv);
783 for (Point p : model.points) {
775d3394 784 float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom;
5129affb 785 colors[p.index] = color(
775d3394 786 (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360,
5129affb
MS
787 constrain(110 - d*6, 0, 100),
788 constrain(130 - 7*d, 0, 100)
789 );
790 }
791 }
792}
f3f5a876 793
4c006f7b
MS
794class Traktor extends SCPattern {
795
796 final int FRAME_WIDTH = 60;
797
798 final BasicParameter speed = new BasicParameter("SPD", 0.5);
799
800 private float[] bass = new float[FRAME_WIDTH];
801 private float[] treble = new float[FRAME_WIDTH];
802
803 private int index = 0;
804 private GraphicEQ eq = null;
805
806 public Traktor(GLucose glucose) {
807 super(glucose);
808 for (int i = 0; i < FRAME_WIDTH; ++i) {
809 bass[i] = 0;
810 treble[i] = 0;
811 }
812 addParameter(speed);
813 }
814
815 public void onActive() {
816 if (eq == null) {
817 eq = new GraphicEQ(lx, 16);
818 eq.slope.setValue(0.6);
819 eq.level.setValue(0.65);
820 eq.range.setValue(0.35);
821 eq.release.setValue(0.4);
822 addParameter(eq.level);
823 addParameter(eq.range);
824 addParameter(eq.attack);
825 addParameter(eq.release);
826 addParameter(eq.slope);
827 }
828 }
829
830 int counter = 0;
831
34327c96 832 public void run(double deltaMs) {
4c006f7b
MS
833 eq.run(deltaMs);
834
835 int stepThresh = (int) (40 - 39*speed.getValuef());
836 counter += deltaMs;
837 if (counter < stepThresh) {
838 return;
839 }
840 counter = counter % stepThresh;
841
842 index = (index + 1) % FRAME_WIDTH;
843
844 float rawBass = eq.getAverageLevel(0, 4);
845 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
846
847 bass[index] = rawBass * rawBass * rawBass * rawBass;
848 treble[index] = rawTreble * rawTreble;
849
850 for (Point p : model.points) {
851 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
852 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
853
854 colors[p.index] = color(
855 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
856 100,
857 constrain(9 * (bass[pos]*model.cy - abs(p.fy - model.cy)), 0, 100)
858 );
859 colors[p.index] = blendColor(colors[p.index], color(
860 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
861 60,
862 constrain(5 * (treble[pos]*.6*model.cy - abs(p.fy - model.cy)), 0, 100)
863
864 ), ADD);
865 }
866 }
867}
6702151a
MS
868
869class ColorFuckerEffect extends SCEffect {
870
871 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
872 BasicParameter sat = new BasicParameter("SAT", 1);
873 BasicParameter bright = new BasicParameter("BRT", 1);
874
875 ColorFuckerEffect(GLucose glucose) {
876 super(glucose);
877 addParameter(hueShift);
878 addParameter(bright);
879 addParameter(sat);
880 }
881
882 public void doApply(int[] colors) {
d626bc9b
MS
883 if (!enabled) {
884 return;
885 }
6702151a
MS
886 float bMod = bright.getValuef();
887 float sMod = sat.getValuef();
888 float hMod = hueShift.getValuef();
889 if (bMod < 1 || sMod < 1 || hMod > 0) {
890 for (int i = 0; i < colors.length; ++i) {
891 colors[i] = color(
892 (hue(colors[i]) + hueShift.getValuef()*360.) % 360,
893 saturation(colors[i]) * sat.getValuef(),
894 brightness(colors[i]) * bright.getValuef()
895 );
896 }
897 }
898 }
899}
348fed66
MS
900
901class BlurEffect extends SCEffect {
902
903 final LXParameter amount = new BasicParameter("AMT", 0);
904 final int[] frame;
905 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
906
907 BlurEffect(GLucose glucose) {
908 super(glucose);
909 addParameter(amount);
910 addModulator(env);
911 frame = new int[lx.total];
912 for (int i = 0; i < frame.length; ++i) {
913 frame[i] = #000000;
914 }
915 }
916
917 public void onEnable() {
918 env.setRangeFromHereTo(1, 400).start();
919 for (int i = 0; i < frame.length; ++i) {
920 frame[i] = #000000;
921 }
922 }
923
924 public void onDisable() {
925 env.setRangeFromHereTo(0, 1000).start();
926 }
927
928 public void doApply(int[] colors) {
929 float amt = env.getValuef() * amount.getValuef();
930 if (amt > 0) {
931 amt = (1 - amt);
932 amt = 1 - (amt*amt*amt);
933 for (int i = 0; i < colors.length; ++i) {
934 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
935 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);
936 }
937 }
938
939 }
940}