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