| 1 | import java.util.Stack; |
| 2 | class Cathedrals extends SCPattern { |
| 3 | |
| 4 | private final BasicParameter xpos = new BasicParameter("XPOS", 0.5); |
| 5 | private final BasicParameter wid = new BasicParameter("WID", 0.5); |
| 6 | private final BasicParameter arms = new BasicParameter("ARMS", 0.5); |
| 7 | private final BasicParameter sat = new BasicParameter("SAT", 0.5); |
| 8 | private GraphicEQ eq; |
| 9 | |
| 10 | Cathedrals(LX lx) { |
| 11 | super(lx); |
| 12 | addParameter(xpos); |
| 13 | addParameter(wid); |
| 14 | addParameter(arms); |
| 15 | addParameter(sat); |
| 16 | } |
| 17 | |
| 18 | void onActive() { |
| 19 | if (eq == null) { |
| 20 | eq = new GraphicEQ(lx, 16); |
| 21 | eq.slope.setValue(0.7); |
| 22 | eq.range.setValue(0.4); |
| 23 | eq.attack.setValue(0.4); |
| 24 | eq.release.setValue(0.4); |
| 25 | addParameter(eq.level); |
| 26 | addParameter(eq.range); |
| 27 | addParameter(eq.attack); |
| 28 | addParameter(eq.release); |
| 29 | addParameter(eq.slope); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | |
| 34 | public void run(double deltaMs) { |
| 35 | eq.run(deltaMs); |
| 36 | float bassLevel = eq.getAverageLevel(0, 4); |
| 37 | float trebleLevel = eq.getAverageLevel(8, 6); |
| 38 | |
| 39 | float falloff = 100 / (2 + 14*wid.getValuef()); |
| 40 | float cx = model.xMin + (model.xMax-model.xMin) * xpos.getValuef(); |
| 41 | float barm = 12 + 60*arms.getValuef()*max(0, 2*(bassLevel-0.1)); |
| 42 | float tarm = 12 + 60*arms.getValuef()*max(0, 2*(trebleLevel-0.1)); |
| 43 | |
| 44 | float arm = 0; |
| 45 | float middle = 0; |
| 46 | |
| 47 | float sf = 100. / (70 - 69.9*sat.getValuef()); |
| 48 | |
| 49 | for (LXPoint p : model.points) { |
| 50 | float d = MAX_FLOAT; |
| 51 | if (p.y > model.cy) { |
| 52 | arm = tarm; |
| 53 | middle = model.yMax * 3/5.; |
| 54 | } else { |
| 55 | arm = barm; |
| 56 | middle = model.yMax * 1/5.; |
| 57 | } |
| 58 | if (abs(p.x - cx) < arm) { |
| 59 | d = min(abs(p.x - cx), abs(p.y - middle)); |
| 60 | } |
| 61 | colors[p.index] = lx.hsb( |
| 62 | (lx.getBaseHuef() + .2*abs(p.y - model.cy)) % 360, |
| 63 | min(100, sf*dist(abs(p.x - cx), p.y, arm, middle)), |
| 64 | constrain(120 - d*falloff, 0, 100)); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | class MidiMusic extends SCPattern { |
| 70 | |
| 71 | private final Stack<LXLayer> newLayers = new Stack<LXLayer>(); |
| 72 | |
| 73 | private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>(); |
| 74 | private final List<LightUp> lights = new ArrayList<LightUp>(); |
| 75 | private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5); |
| 76 | |
| 77 | private final List<Sweep> sweeps = new ArrayList<Sweep>(); |
| 78 | |
| 79 | private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500); |
| 80 | private boolean sparkleDirection = true; |
| 81 | private float sparkleBright = 100; |
| 82 | |
| 83 | private final BasicParameter wave = new BasicParameter("WAVE", 0); |
| 84 | |
| 85 | MidiMusic(LX lx) { |
| 86 | super(lx); |
| 87 | addParameter(lightSize); |
| 88 | addParameter(wave); |
| 89 | addModulator(sparkle).setValue(1); |
| 90 | } |
| 91 | |
| 92 | void onReset() { |
| 93 | for (LightUp light : lights) { |
| 94 | light.noteOff(null); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | class Sweep extends LXLayer { |
| 99 | |
| 100 | final LinearEnvelope position = new LinearEnvelope(0, 1, 1000); |
| 101 | float bright = 100; |
| 102 | float falloff = 10; |
| 103 | |
| 104 | Sweep() { |
| 105 | addModulator(position); |
| 106 | } |
| 107 | |
| 108 | public void run(double deltaMs, color[] colors) { |
| 109 | if (!position.isRunning()) { |
| 110 | return; |
| 111 | } |
| 112 | float posf = position.getValuef(); |
| 113 | for (LXPoint p : model.points) { |
| 114 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
| 115 | (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360, |
| 116 | 100, |
| 117 | max(0, bright - posf*100 - falloff*abs(p.y - posf*model.yMax)) |
| 118 | ), ADD); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | class LightUp extends LXLayer { |
| 124 | |
| 125 | private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0); |
| 126 | private final Accelerator yPos = new Accelerator(0, 0, 0); |
| 127 | private float xPos; |
| 128 | |
| 129 | LightUp() { |
| 130 | addModulator(brt); |
| 131 | addModulator(yPos); |
| 132 | } |
| 133 | |
| 134 | boolean isAvailable() { |
| 135 | return brt.getValuef() <= 0; |
| 136 | } |
| 137 | |
| 138 | void noteOn(Note note) { |
| 139 | xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 28., 0, 1)); |
| 140 | yPos.setValue(lerp(20, model.yMax*.72, note.getVelocity() / 127.)).stop(); |
| 141 | brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start(); |
| 142 | } |
| 143 | |
| 144 | void noteOff(Note note) { |
| 145 | yPos.setVelocity(0).setAcceleration(-380).start(); |
| 146 | brt.setRangeFromHereTo(0, 1000).start(); |
| 147 | } |
| 148 | |
| 149 | public void run(double deltaMs, color[] colors) { |
| 150 | float bVal = brt.getValuef(); |
| 151 | if (bVal <= 0) { |
| 152 | return; |
| 153 | } |
| 154 | float yVal = yPos.getValuef(); |
| 155 | for (LXPoint p : model.points) { |
| 156 | float falloff = 6 - 5*lightSize.getValuef(); |
| 157 | float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal)); |
| 158 | if (b > 0) { |
| 159 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
| 160 | (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360, |
| 161 | 100, |
| 162 | b |
| 163 | ), ADD); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | private LightUp getLight() { |
| 170 | for (LightUp light : lights) { |
| 171 | if (light.isAvailable()) { |
| 172 | return light; |
| 173 | } |
| 174 | } |
| 175 | LightUp newLight = new LightUp(); |
| 176 | lights.add(newLight); |
| 177 | synchronized(newLayers) { |
| 178 | newLayers.push(newLight); |
| 179 | } |
| 180 | return newLight; |
| 181 | } |
| 182 | |
| 183 | private Sweep getSweep() { |
| 184 | for (Sweep s : sweeps) { |
| 185 | if (!s.position.isRunning()) { |
| 186 | return s; |
| 187 | } |
| 188 | } |
| 189 | Sweep newSweep = new Sweep(); |
| 190 | sweeps.add(newSweep); |
| 191 | synchronized(newLayers) { |
| 192 | newLayers.push(newSweep); |
| 193 | } |
| 194 | return newSweep; |
| 195 | } |
| 196 | |
| 197 | public synchronized boolean noteOn(Note note) { |
| 198 | if (note.getChannel() == 0) { |
| 199 | LightUp light = getLight(); |
| 200 | lightMap.put(note.getPitch(), light); |
| 201 | light.noteOn(note); |
| 202 | } else if (note.getChannel() == 1) { |
| 203 | } else if (note.getChannel() == 9) { |
| 204 | if (note.getVelocity() > 0) { |
| 205 | switch (note.getPitch()) { |
| 206 | case 36: |
| 207 | Sweep s = getSweep(); |
| 208 | s.bright = 50 + note.getVelocity() / 127. * 50; |
| 209 | s.falloff = 20 - note.getVelocity() / 127. * 17; |
| 210 | s.position.trigger(); |
| 211 | break; |
| 212 | case 37: |
| 213 | sparkleBright = note.getVelocity() / 127. * 100; |
| 214 | sparkleDirection = true; |
| 215 | sparkle.trigger(); |
| 216 | break; |
| 217 | case 38: |
| 218 | sparkleBright = note.getVelocity() / 127. * 100; |
| 219 | sparkleDirection = false; |
| 220 | sparkle.trigger(); |
| 221 | break; |
| 222 | case 39: |
| 223 | effects.boom.trigger(); |
| 224 | break; |
| 225 | case 40: |
| 226 | //effects.flash.trigger(); |
| 227 | break; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | return true; |
| 232 | } |
| 233 | |
| 234 | public synchronized boolean noteOff(Note note) { |
| 235 | if (note.getChannel() == 0) { |
| 236 | LightUp light = lightMap.get(note.getPitch()); |
| 237 | if (light != null) { |
| 238 | light.noteOff(note); |
| 239 | } |
| 240 | } |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | final float[] wval = new float[16]; |
| 245 | float wavoff = 0; |
| 246 | |
| 247 | public synchronized void run(double deltaMs) { |
| 248 | wavoff += deltaMs * .001; |
| 249 | for (int i = 0; i < wval.length; ++i) { |
| 250 | wval[i] = model.cy + 0.2 * model.yMax/2. * sin(wavoff + i / 1.9); |
| 251 | } |
| 252 | float sparklePos = (sparkleDirection ? sparkle.getValuef() : (1 - sparkle.getValuef())) * (Cube.POINTS_PER_STRIP)/2.; |
| 253 | float maxBright = sparkleBright * (1 - sparkle.getValuef()); |
| 254 | for (Strip s : model.strips) { |
| 255 | int i = 0; |
| 256 | for (LXPoint p : s.points) { |
| 257 | int wavi = (int) constrain(p.x / model.xMax * wval.length, 0, wval.length-1); |
| 258 | float wavb = max(0, wave.getValuef()*100. - 8.*abs(p.y - wval[wavi])); |
| 259 | colors[p.index] = lx.hsb( |
| 260 | (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360, |
| 261 | 100, |
| 262 | constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100) |
| 263 | ); |
| 264 | ++i; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | if (!newLayers.isEmpty()) { |
| 269 | synchronized(newLayers) { |
| 270 | while (!newLayers.isEmpty()) { |
| 271 | addLayer(newLayers.pop()); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | class Pulley extends SCPattern { |
| 279 | |
| 280 | final int NUM_DIVISIONS = 16; |
| 281 | private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS]; |
| 282 | private final Click[] delays = new Click[NUM_DIVISIONS]; |
| 283 | |
| 284 | private final Click reset = new Click(9000); |
| 285 | private boolean isRising = false; |
| 286 | |
| 287 | private BasicParameter sz = new BasicParameter("SIZE", 0.5); |
| 288 | private BasicParameter beatAmount = new BasicParameter("BEAT", 0); |
| 289 | |
| 290 | Pulley(LX lx) { |
| 291 | super(lx); |
| 292 | for (int i = 0; i < NUM_DIVISIONS; ++i) { |
| 293 | addModulator(gravity[i] = new Accelerator(0, 0, 0)); |
| 294 | addModulator(delays[i] = new Click(0)); |
| 295 | } |
| 296 | addModulator(reset).start(); |
| 297 | addParameter(sz); |
| 298 | addParameter(beatAmount); |
| 299 | trigger(); |
| 300 | |
| 301 | } |
| 302 | |
| 303 | private void trigger() { |
| 304 | isRising = !isRising; |
| 305 | int i = 0; |
| 306 | for (Accelerator g : gravity) { |
| 307 | if (isRising) { |
| 308 | g.setSpeed(random(20, 33), 0).start(); |
| 309 | } else { |
| 310 | g.setVelocity(0).setAcceleration(-420); |
| 311 | delays[i].setDuration(random(0, 500)).trigger(); |
| 312 | } |
| 313 | ++i; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | public void run(double deltaMs) { |
| 318 | if (reset.click()) { |
| 319 | trigger(); |
| 320 | } |
| 321 | |
| 322 | if (isRising) { |
| 323 | // Fucking A, had to comment this all out because of that bizarre |
| 324 | // Processing bug where some simple loop takes an absurd amount of |
| 325 | // time, must be some pre-processor bug |
| 326 | // for (Accelerator g : gravity) { |
| 327 | // if (g.getValuef() > model.yMax) { |
| 328 | // g.stop(); |
| 329 | // } else if (g.getValuef() > model.yMax*.55) { |
| 330 | // if (g.getVelocityf() > 10) { |
| 331 | // g.setAcceleration(-16); |
| 332 | // } else { |
| 333 | // g.setAcceleration(0); |
| 334 | // } |
| 335 | // } |
| 336 | // } |
| 337 | } else { |
| 338 | int j = 0; |
| 339 | for (Click d : delays) { |
| 340 | if (d.click()) { |
| 341 | gravity[j].start(); |
| 342 | d.stop(); |
| 343 | } |
| 344 | ++j; |
| 345 | } |
| 346 | for (Accelerator g : gravity) { |
| 347 | if (g.getValuef() < 0) { |
| 348 | g.setValue(-g.getValuef()); |
| 349 | g.setVelocity(-g.getVelocityf() * random(0.74, 0.84)); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | // A little silliness to test the grid API |
| 355 | if (midiEngine != null && midiEngine.getFocusedPattern() == this) { |
| 356 | for (int i = 0; i < 5; ++i) { |
| 357 | for (int j = 0; j < 8; ++j) { |
| 358 | int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1); |
| 359 | float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax); |
| 360 | midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3); |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | float fPos = 1 - lx.tempo.rampf(); |
| 366 | if (fPos < .2) { |
| 367 | fPos = .2 + 4 * (.2 - fPos); |
| 368 | } |
| 369 | float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48); |
| 370 | for (LXPoint p : model.points) { |
| 371 | int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1); |
| 372 | colors[p.index] = lx.hsb( |
| 373 | (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360, |
| 374 | constrain(130 - p.y*.8, 0, 100), |
| 375 | max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff) |
| 376 | ); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | class ViolinWave extends SCPattern { |
| 382 | |
| 383 | BasicParameter level = new BasicParameter("LVL", 0.45); |
| 384 | BasicParameter range = new BasicParameter("RNG", 0.5); |
| 385 | BasicParameter edge = new BasicParameter("EDG", 0.5); |
| 386 | BasicParameter release = new BasicParameter("RLS", 0.5); |
| 387 | BasicParameter speed = new BasicParameter("SPD", 0.5); |
| 388 | BasicParameter amp = new BasicParameter("AMP", 0.25); |
| 389 | BasicParameter period = new BasicParameter("WAVE", 0.5); |
| 390 | BasicParameter pSize = new BasicParameter("PSIZE", 0.5); |
| 391 | BasicParameter pSpeed = new BasicParameter("PSPD", 0.5); |
| 392 | BasicParameter pDensity = new BasicParameter("PDENS", 0.25); |
| 393 | |
| 394 | LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10); |
| 395 | |
| 396 | ViolinWave(LX lx) { |
| 397 | super(lx); |
| 398 | addParameter(level); |
| 399 | addParameter(edge); |
| 400 | addParameter(range); |
| 401 | addParameter(release); |
| 402 | addParameter(speed); |
| 403 | addParameter(amp); |
| 404 | addParameter(period); |
| 405 | addParameter(pSize); |
| 406 | addParameter(pSpeed); |
| 407 | addParameter(pDensity); |
| 408 | |
| 409 | addModulator(dbValue); |
| 410 | } |
| 411 | |
| 412 | final List<Particle> particles = new ArrayList<Particle>(); |
| 413 | |
| 414 | class Particle { |
| 415 | |
| 416 | LinearEnvelope x = new LinearEnvelope(0, 0, 0); |
| 417 | LinearEnvelope y = new LinearEnvelope(0, 0, 0); |
| 418 | |
| 419 | Particle() { |
| 420 | addModulator(x); |
| 421 | addModulator(y); |
| 422 | } |
| 423 | |
| 424 | Particle trigger(boolean direction) { |
| 425 | float xInit = random(model.xMin, model.xMax); |
| 426 | float time = 3000 - 2500*pSpeed.getValuef(); |
| 427 | x.setRange(xInit, xInit + random(-40, 40), time).trigger(); |
| 428 | y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger(); |
| 429 | return this; |
| 430 | } |
| 431 | |
| 432 | boolean isActive() { |
| 433 | return x.isRunning() || y.isRunning(); |
| 434 | } |
| 435 | |
| 436 | public void run(double deltaMs) { |
| 437 | if (!isActive()) { |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | float pFalloff = (30 - 27*pSize.getValuef()); |
| 442 | for (LXPoint p : model.points) { |
| 443 | float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef())); |
| 444 | if (b > 0) { |
| 445 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
| 446 | lx.getBaseHuef(), 20, b |
| 447 | ), ADD); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | float[] centers = new float[30]; |
| 454 | double accum = 0; |
| 455 | boolean rising = true; |
| 456 | |
| 457 | void fireParticle(boolean direction) { |
| 458 | boolean gotOne = false; |
| 459 | for (Particle p : particles) { |
| 460 | if (!p.isActive()) { |
| 461 | p.trigger(direction); |
| 462 | return; |
| 463 | } |
| 464 | } |
| 465 | particles.add(new Particle().trigger(direction)); |
| 466 | } |
| 467 | |
| 468 | public void run(double deltaMs) { |
| 469 | accum += deltaMs / (1000. - 900.*speed.getValuef()); |
| 470 | for (int i = 0; i < centers.length; ++i) { |
| 471 | centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef()))); |
| 472 | } |
| 473 | |
| 474 | float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.); |
| 475 | float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference); |
| 476 | if (dB > dbValue.getValuef()) { |
| 477 | rising = true; |
| 478 | dbValue.setRangeFromHereTo(dB, 10).trigger(); |
| 479 | } else { |
| 480 | if (rising) { |
| 481 | for (int j = 0; j < pDensity.getValuef()*3; ++j) { |
| 482 | fireParticle(true); |
| 483 | fireParticle(false); |
| 484 | } |
| 485 | } |
| 486 | rising = false; |
| 487 | dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger(); |
| 488 | } |
| 489 | float edg = 1 + edge.getValuef() * 40; |
| 490 | float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy); |
| 491 | float val = max(2, dbValue.getValuef()); |
| 492 | |
| 493 | for (LXPoint p : model.points) { |
| 494 | int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin)); |
| 495 | float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx); |
| 496 | colors[p.index] = lx.hsb( |
| 497 | (lx.getBaseHuef() + abs(p.x - model.cx)) % 360, |
| 498 | min(100, 20 + 8*abs(p.y - centers[ci])), |
| 499 | constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100) |
| 500 | ); |
| 501 | } |
| 502 | |
| 503 | for (Particle p : particles) { |
| 504 | p.run(deltaMs); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | class BouncyBalls extends SCPattern { |
| 510 | |
| 511 | static final int NUM_BALLS = 6; |
| 512 | |
| 513 | class BouncyBall { |
| 514 | |
| 515 | Accelerator yPos; |
| 516 | TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000)); |
| 517 | float zPos; |
| 518 | |
| 519 | BouncyBall(int i) { |
| 520 | addModulator(xPos.setBasis(random(0, TWO_PI)).start()); |
| 521 | addModulator(yPos = new Accelerator(0, 0, 0)); |
| 522 | zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.)); |
| 523 | } |
| 524 | |
| 525 | void bounce(float midiVel) { |
| 526 | float v = 100 + 8*midiVel; |
| 527 | yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start(); |
| 528 | } |
| 529 | |
| 530 | float getAccel(float v, float oneBeat) { |
| 531 | return -2*v / oneBeat; |
| 532 | } |
| 533 | |
| 534 | void run(double deltaMs) { |
| 535 | float flrLevel = flr.getValuef() * model.xMax/2.; |
| 536 | if (yPos.getValuef() < flrLevel) { |
| 537 | if (yPos.getVelocity() < -50) { |
| 538 | yPos.setValue(2*flrLevel-yPos.getValuef()); |
| 539 | float v = -yPos.getVelocityf() * bounce.getValuef(); |
| 540 | yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())); |
| 541 | } else { |
| 542 | yPos.setValue(flrLevel).stop(); |
| 543 | } |
| 544 | } |
| 545 | float falloff = 130.f / (12 + blobSize.getValuef() * 36); |
| 546 | float xv = xPos.getValuef(); |
| 547 | float yv = yPos.getValuef(); |
| 548 | |
| 549 | for (LXPoint p : model.points) { |
| 550 | float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos)); |
| 551 | float b = constrain(130 - falloff*d, 0, 100); |
| 552 | if (b > 0) { |
| 553 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
| 554 | (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360, |
| 555 | max(0, 100 - .45*(p.y - flrLevel)), |
| 556 | b |
| 557 | ), ADD); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | final BouncyBall[] balls = new BouncyBall[NUM_BALLS]; |
| 564 | |
| 565 | final BasicParameter bounce = new BasicParameter("BNC", .8); |
| 566 | final BasicParameter flr = new BasicParameter("FLR", 0); |
| 567 | final BasicParameter blobSize = new BasicParameter("SIZE", 0.5); |
| 568 | |
| 569 | BouncyBalls(LX lx) { |
| 570 | super(lx); |
| 571 | for (int i = 0; i < balls.length; ++i) { |
| 572 | balls[i] = new BouncyBall(i); |
| 573 | } |
| 574 | addParameter(bounce); |
| 575 | addParameter(flr); |
| 576 | addParameter(blobSize); |
| 577 | } |
| 578 | |
| 579 | public void run(double deltaMs) { |
| 580 | setColors(#000000); |
| 581 | for (BouncyBall b : balls) { |
| 582 | b.run(deltaMs); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | public boolean noteOn(Note note) { |
| 587 | int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS; |
| 588 | balls[pitch].bounce(note.getVelocity()); |
| 589 | return true; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | class SpaceTime extends SCPattern { |
| 594 | |
| 595 | SinLFO pos = new SinLFO(0, 1, 3000); |
| 596 | SinLFO rate = new SinLFO(1000, 9000, 13000); |
| 597 | SinLFO falloff = new SinLFO(10, 70, 5000); |
| 598 | float angle = 0; |
| 599 | |
| 600 | BasicParameter rateParameter = new BasicParameter("RATE", 0.5); |
| 601 | BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5); |
| 602 | |
| 603 | |
| 604 | public SpaceTime(LX lx) { |
| 605 | super(lx); |
| 606 | |
| 607 | addModulator(pos).trigger(); |
| 608 | addModulator(rate).trigger(); |
| 609 | addModulator(falloff).trigger(); |
| 610 | pos.modulateDurationBy(rate); |
| 611 | addParameter(rateParameter); |
| 612 | addParameter(sizeParameter); |
| 613 | } |
| 614 | |
| 615 | public void onParameterChanged(LXParameter parameter) { |
| 616 | if (parameter == rateParameter) { |
| 617 | rate.stop().setValue(9000 - 8000*parameter.getValuef()); |
| 618 | } else if (parameter == sizeParameter) { |
| 619 | falloff.stop().setValue(70 - 60*parameter.getValuef()); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | void run(double deltaMs) { |
| 624 | angle += deltaMs * 0.0007; |
| 625 | float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle)); |
| 626 | float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle)); |
| 627 | |
| 628 | float pVal = pos.getValuef(); |
| 629 | float fVal = falloff.getValuef(); |
| 630 | |
| 631 | int s = 0; |
| 632 | for (Strip strip : model.strips) { |
| 633 | int i = 0; |
| 634 | for (LXPoint p : strip.points) { |
| 635 | colors[p.index] = lx.hsb( |
| 636 | (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360, |
| 637 | constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100), |
| 638 | max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1))) |
| 639 | ); |
| 640 | ++i; |
| 641 | } |
| 642 | ++s; |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | class Swarm extends SCPattern { |
| 648 | |
| 649 | SawLFO offset = new SawLFO(0, 1, 1000); |
| 650 | SinLFO rate = new SinLFO(350, 1200, 63000); |
| 651 | SinLFO falloff = new SinLFO(15, 50, 17000); |
| 652 | SinLFO fX = new SinLFO(model.xMin, model.xMax, 19000); |
| 653 | SinLFO fY = new SinLFO(model.yMin, model.yMax, 11000); |
| 654 | SinLFO hOffX = new SinLFO(model.xMin, model.xMax, 13000); |
| 655 | |
| 656 | public Swarm(LX lx) { |
| 657 | super(lx); |
| 658 | |
| 659 | addModulator(offset).trigger(); |
| 660 | addModulator(rate).trigger(); |
| 661 | addModulator(falloff).trigger(); |
| 662 | addModulator(fX).trigger(); |
| 663 | addModulator(fY).trigger(); |
| 664 | addModulator(hOffX).trigger(); |
| 665 | offset.modulateDurationBy(rate); |
| 666 | } |
| 667 | |
| 668 | float modDist(float v1, float v2, float mod) { |
| 669 | v1 = v1 % mod; |
| 670 | v2 = v2 % mod; |
| 671 | if (v2 > v1) { |
| 672 | return min(v2-v1, v1+mod-v2); |
| 673 | } |
| 674 | else { |
| 675 | return min(v1-v2, v2+mod-v1); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | void run(double deltaMs) { |
| 680 | float s = 0; |
| 681 | for (Strip strip : model.strips) { |
| 682 | int i = 0; |
| 683 | for (LXPoint p : strip.points) { |
| 684 | float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.); |
| 685 | colors[p.index] = lx.hsb( |
| 686 | (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360, |
| 687 | constrain(80 + 40 * fV, 0, 100), |
| 688 | constrain(100 - |
| 689 | (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100) |
| 690 | ); |
| 691 | ++i; |
| 692 | } |
| 693 | ++s; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | class SwipeTransition extends LXTransition { |
| 699 | |
| 700 | final BasicParameter bleed = new BasicParameter("WIDTH", 0.5); |
| 701 | |
| 702 | SwipeTransition(LX lx) { |
| 703 | super(lx); |
| 704 | setDuration(5000); |
| 705 | addParameter(bleed); |
| 706 | } |
| 707 | |
| 708 | void computeBlend(int[] c1, int[] c2, double progress) { |
| 709 | float bleedf = 10 + bleed.getValuef() * 200.; |
| 710 | float xPos = (float) (-bleedf + progress * (model.xMax + bleedf)); |
| 711 | for (LXPoint p : model.points) { |
| 712 | float d = (p.x - xPos) / bleedf; |
| 713 | if (d < 0) { |
| 714 | colors[p.index] = c2[p.index]; |
| 715 | } else if (d > 1) { |
| 716 | colors[p.index] = c1[p.index]; |
| 717 | } else { |
| 718 | colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB); |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | class BassPod extends SCPattern { |
| 725 | |
| 726 | private GraphicEQ eq = null; |
| 727 | |
| 728 | private final BasicParameter clr = new BasicParameter("CLR", 0.5); |
| 729 | |
| 730 | public BassPod(LX lx) { |
| 731 | super(lx); |
| 732 | addParameter(clr); |
| 733 | } |
| 734 | |
| 735 | void onActive() { |
| 736 | if (eq == null) { |
| 737 | eq = new GraphicEQ(lx, 16); |
| 738 | eq.range.setValue(0.4); |
| 739 | eq.level.setValue(0.4); |
| 740 | eq.slope.setValue(0.6); |
| 741 | addParameter(eq.level); |
| 742 | addParameter(eq.range); |
| 743 | addParameter(eq.attack); |
| 744 | addParameter(eq.release); |
| 745 | addParameter(eq.slope); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | public void run(double deltaMs) { |
| 750 | eq.run(deltaMs); |
| 751 | |
| 752 | float bassLevel = eq.getAverageLevel(0, 5); |
| 753 | |
| 754 | float satBase = bassLevel*480*clr.getValuef(); |
| 755 | |
| 756 | for (LXPoint p : model.points) { |
| 757 | int avgIndex = (int) constrain(1 + abs(p.x-model.cx)/(model.cx)*(eq.numBands-5), 0, eq.numBands-5); |
| 758 | float value = 0; |
| 759 | for (int i = avgIndex; i < avgIndex + 5; ++i) { |
| 760 | value += eq.getLevel(i); |
| 761 | } |
| 762 | value /= 5.; |
| 763 | |
| 764 | float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100); |
| 765 | colors[p.index] = lx.hsb( |
| 766 | (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360, |
| 767 | constrain(satBase - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100), |
| 768 | b |
| 769 | ); |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | |
| 775 | class CubeEQ extends SCPattern { |
| 776 | |
| 777 | private GraphicEQ eq = null; |
| 778 | |
| 779 | private final BasicParameter edge = new BasicParameter("EDGE", 0.5); |
| 780 | private final BasicParameter clr = new BasicParameter("CLR", 0.5); |
| 781 | private final BasicParameter blockiness = new BasicParameter("BLK", 0.5); |
| 782 | |
| 783 | public CubeEQ(LX lx) { |
| 784 | super(lx); |
| 785 | } |
| 786 | |
| 787 | void onActive() { |
| 788 | if (eq == null) { |
| 789 | eq = new GraphicEQ(lx, 16); |
| 790 | addParameter(eq.level); |
| 791 | addParameter(eq.range); |
| 792 | addParameter(eq.attack); |
| 793 | addParameter(eq.release); |
| 794 | addParameter(eq.slope); |
| 795 | addParameter(edge); |
| 796 | addParameter(clr); |
| 797 | addParameter(blockiness); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | public void run(double deltaMs) { |
| 802 | eq.run(deltaMs); |
| 803 | |
| 804 | float edgeConst = 2 + 30*edge.getValuef(); |
| 805 | float clrConst = 1.1 + clr.getValuef(); |
| 806 | |
| 807 | for (LXPoint p : model.points) { |
| 808 | float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4); |
| 809 | int avgFloor = (int) avgIndex; |
| 810 | |
| 811 | float leftVal = eq.getLevel(avgFloor); |
| 812 | float rightVal = eq.getLevel(avgFloor+1); |
| 813 | float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor); |
| 814 | |
| 815 | float chunkyValue = ( |
| 816 | eq.getLevel(avgFloor/4*4) + |
| 817 | eq.getLevel(avgFloor/4*4 + 1) + |
| 818 | eq.getLevel(avgFloor/4*4 + 2) + |
| 819 | eq.getLevel(avgFloor/4*4 + 3) |
| 820 | ) / 4.; |
| 821 | |
| 822 | float value = lerp(smoothValue, chunkyValue, blockiness.getValuef()); |
| 823 | |
| 824 | float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100); |
| 825 | colors[p.index] = lx.hsb( |
| 826 | (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360, |
| 827 | 100, |
| 828 | b |
| 829 | ); |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | class BoomEffect extends LXEffect { |
| 835 | |
| 836 | final BasicParameter falloff = new BasicParameter("WIDTH", 0.5); |
| 837 | final BasicParameter speed = new BasicParameter("SPD", 0.5); |
| 838 | final BasicParameter bright = new BasicParameter("BRT", 1.0); |
| 839 | final BasicParameter sat = new BasicParameter("SAT", 0.2); |
| 840 | List<Layer> layers = new ArrayList<Layer>(); |
| 841 | final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10; |
| 842 | |
| 843 | class Layer { |
| 844 | LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300); |
| 845 | |
| 846 | Layer() { |
| 847 | addModulator(boom); |
| 848 | trigger(); |
| 849 | } |
| 850 | |
| 851 | void trigger() { |
| 852 | float falloffv = falloffv(); |
| 853 | boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300); |
| 854 | boom.trigger(); |
| 855 | } |
| 856 | |
| 857 | void apply(int[] colors) { |
| 858 | float brightv = 100 * bright.getValuef(); |
| 859 | float falloffv = falloffv(); |
| 860 | float satv = sat.getValuef() * 100; |
| 861 | float huev = lx.getBaseHuef(); |
| 862 | for (LXPoint p : model.points) { |
| 863 | colors[p.index] = blendColor( |
| 864 | colors[p.index], |
| 865 | 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)), |
| 866 | ADD); |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | BoomEffect(LX lx) { |
| 872 | super(lx, true); |
| 873 | addParameter(falloff); |
| 874 | addParameter(speed); |
| 875 | addParameter(bright); |
| 876 | addParameter(sat); |
| 877 | } |
| 878 | |
| 879 | public void onEnable() { |
| 880 | for (Layer l : layers) { |
| 881 | if (!l.boom.isRunning()) { |
| 882 | l.trigger(); |
| 883 | return; |
| 884 | } |
| 885 | } |
| 886 | layers.add(new Layer()); |
| 887 | } |
| 888 | |
| 889 | private float falloffv() { |
| 890 | return 20 - 19 * falloff.getValuef(); |
| 891 | } |
| 892 | |
| 893 | public void onTrigger() { |
| 894 | onEnable(); |
| 895 | } |
| 896 | |
| 897 | public void apply(int[] colors) { |
| 898 | for (Layer l : layers) { |
| 899 | if (l.boom.isRunning()) { |
| 900 | l.apply(colors); |
| 901 | } |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | public class PianoKeyPattern extends SCPattern { |
| 907 | |
| 908 | final LinearEnvelope[] cubeBrt; |
| 909 | final SinLFO base[]; |
| 910 | final BasicParameter attack = new BasicParameter("ATK", 0.1); |
| 911 | final BasicParameter release = new BasicParameter("REL", 0.5); |
| 912 | final BasicParameter level = new BasicParameter("AMB", 0.6); |
| 913 | |
| 914 | PianoKeyPattern(LX lx) { |
| 915 | super(lx); |
| 916 | |
| 917 | addParameter(attack); |
| 918 | addParameter(release); |
| 919 | addParameter(level); |
| 920 | cubeBrt = new LinearEnvelope[model.cubes.size() / 4]; |
| 921 | for (int i = 0; i < cubeBrt.length; ++i) { |
| 922 | addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100)); |
| 923 | } |
| 924 | base = new SinLFO[model.cubes.size() / 12]; |
| 925 | for (int i = 0; i < base.length; ++i) { |
| 926 | addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger(); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | private float getAttackTime() { |
| 931 | return 15 + attack.getValuef()*attack.getValuef() * 2000; |
| 932 | } |
| 933 | |
| 934 | private float getReleaseTime() { |
| 935 | return 15 + release.getValuef() * 3000; |
| 936 | } |
| 937 | |
| 938 | private LinearEnvelope getEnvelope(int index) { |
| 939 | return cubeBrt[index % cubeBrt.length]; |
| 940 | } |
| 941 | |
| 942 | private SinLFO getBase(int index) { |
| 943 | return base[index % base.length]; |
| 944 | } |
| 945 | |
| 946 | public boolean noteOn(Note note) { |
| 947 | LinearEnvelope env = getEnvelope(note.getPitch()); |
| 948 | env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start(); |
| 949 | return true; |
| 950 | } |
| 951 | |
| 952 | public boolean noteOff(Note note) { |
| 953 | getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start(); |
| 954 | return true; |
| 955 | } |
| 956 | |
| 957 | public void run(double deltaMs) { |
| 958 | int i = 0; |
| 959 | float huef = lx.getBaseHuef(); |
| 960 | float levelf = level.getValuef(); |
| 961 | for (Cube c : model.cubes) { |
| 962 | float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef()); |
| 963 | setColor(c, lx.hsb( |
| 964 | (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360, |
| 965 | min(100, 120*v), |
| 966 | 100*v |
| 967 | )); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | class CrossSections extends SCPattern { |
| 973 | |
| 974 | final SinLFO x = new SinLFO(0, model.xMax, 5000); |
| 975 | final SinLFO y = new SinLFO(0, model.yMax, 6000); |
| 976 | final SinLFO z = new SinLFO(0, model.zMax, 7000); |
| 977 | |
| 978 | final BasicParameter xw = new BasicParameter("XWID", 0.3); |
| 979 | final BasicParameter yw = new BasicParameter("YWID", 0.3); |
| 980 | final BasicParameter zw = new BasicParameter("ZWID", 0.3); |
| 981 | final BasicParameter xr = new BasicParameter("XRAT", 0.7); |
| 982 | final BasicParameter yr = new BasicParameter("YRAT", 0.6); |
| 983 | final BasicParameter zr = new BasicParameter("ZRAT", 0.5); |
| 984 | final BasicParameter xl = new BasicParameter("XLEV", 1); |
| 985 | final BasicParameter yl = new BasicParameter("YLEV", 1); |
| 986 | final BasicParameter zl = new BasicParameter("ZLEV", 0.5); |
| 987 | |
| 988 | |
| 989 | CrossSections(LX lx) { |
| 990 | super(lx); |
| 991 | addModulator(x).trigger(); |
| 992 | addModulator(y).trigger(); |
| 993 | addModulator(z).trigger(); |
| 994 | addParams(); |
| 995 | } |
| 996 | |
| 997 | protected void addParams() { |
| 998 | addParameter(xr); |
| 999 | addParameter(yr); |
| 1000 | addParameter(zr); |
| 1001 | addParameter(xw); |
| 1002 | addParameter(xl); |
| 1003 | addParameter(yl); |
| 1004 | addParameter(zl); |
| 1005 | addParameter(yw); |
| 1006 | addParameter(zw); |
| 1007 | } |
| 1008 | |
| 1009 | void onParameterChanged(LXParameter p) { |
| 1010 | if (p == xr) { |
| 1011 | x.setDuration(10000 - 8800*p.getValuef()); |
| 1012 | } else if (p == yr) { |
| 1013 | y.setDuration(10000 - 9000*p.getValuef()); |
| 1014 | } else if (p == zr) { |
| 1015 | z.setDuration(10000 - 9000*p.getValuef()); |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | float xv, yv, zv; |
| 1020 | |
| 1021 | protected void updateXYZVals() { |
| 1022 | xv = x.getValuef(); |
| 1023 | yv = y.getValuef(); |
| 1024 | zv = z.getValuef(); |
| 1025 | } |
| 1026 | |
| 1027 | public void run(double deltaMs) { |
| 1028 | updateXYZVals(); |
| 1029 | |
| 1030 | float xlv = 100*xl.getValuef(); |
| 1031 | float ylv = 100*yl.getValuef(); |
| 1032 | float zlv = 100*zl.getValuef(); |
| 1033 | |
| 1034 | float xwv = 100. / (10 + 40*xw.getValuef()); |
| 1035 | float ywv = 100. / (10 + 40*yw.getValuef()); |
| 1036 | float zwv = 100. / (10 + 40*zw.getValuef()); |
| 1037 | |
| 1038 | for (LXPoint p : model.points) { |
| 1039 | color c = 0; |
| 1040 | c = blendColor(c, lx.hsb( |
| 1041 | (lx.getBaseHuef() + p.x/10 + p.y/3) % 360, |
| 1042 | constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100), |
| 1043 | max(0, xlv - xwv*abs(p.x - xv)) |
| 1044 | ), ADD); |
| 1045 | c = blendColor(c, lx.hsb( |
| 1046 | (lx.getBaseHuef() + 80 + p.y/10) % 360, |
| 1047 | constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100), |
| 1048 | max(0, ylv - ywv*abs(p.y - yv)) |
| 1049 | ), ADD); |
| 1050 | c = blendColor(c, lx.hsb( |
| 1051 | (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360, |
| 1052 | constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100), |
| 1053 | max(0, zlv - zwv*abs(p.z - zv)) |
| 1054 | ), ADD); |
| 1055 | colors[p.index] = c; |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | class Blinders extends SCPattern { |
| 1061 | |
| 1062 | final SinLFO[] m; |
| 1063 | final TriangleLFO r; |
| 1064 | final SinLFO s; |
| 1065 | final TriangleLFO hs; |
| 1066 | |
| 1067 | public Blinders(LX lx) { |
| 1068 | super(lx); |
| 1069 | m = new SinLFO[12]; |
| 1070 | for (int i = 0; i < m.length; ++i) { |
| 1071 | addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger(); |
| 1072 | } |
| 1073 | addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger(); |
| 1074 | addModulator(s = new SinLFO(-20, 275, 11000)).trigger(); |
| 1075 | addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger(); |
| 1076 | s.modulateDurationBy(r); |
| 1077 | } |
| 1078 | |
| 1079 | public void run(double deltaMs) { |
| 1080 | float hv = lx.getBaseHuef(); |
| 1081 | int si = 0; |
| 1082 | for (Strip strip : model.strips) { |
| 1083 | int i = 0; |
| 1084 | float mv = m[si % m.length].getValuef(); |
| 1085 | for (LXPoint p : strip.points) { |
| 1086 | colors[p.index] = lx.hsb( |
| 1087 | (hv + p.z + p.y*hs.getValuef()) % 360, |
| 1088 | min(100, abs(p.x - s.getValuef())/2.), |
| 1089 | max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.)) |
| 1090 | ); |
| 1091 | ++i; |
| 1092 | } |
| 1093 | ++si; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | class Psychedelia extends SCPattern { |
| 1099 | |
| 1100 | final int NUM = 3; |
| 1101 | SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000); |
| 1102 | SinLFO s = new SinLFO(-20, 147, 11000); |
| 1103 | TriangleLFO h = new TriangleLFO(0, 240, 19000); |
| 1104 | SinLFO c = new SinLFO(-.2, .8, 31000); |
| 1105 | |
| 1106 | Psychedelia(LX lx) { |
| 1107 | super(lx); |
| 1108 | addModulator(m).trigger(); |
| 1109 | addModulator(s).trigger(); |
| 1110 | addModulator(h).trigger(); |
| 1111 | addModulator(c).trigger(); |
| 1112 | } |
| 1113 | |
| 1114 | void run(double deltaMs) { |
| 1115 | float huev = h.getValuef(); |
| 1116 | float cv = c.getValuef(); |
| 1117 | float sv = s.getValuef(); |
| 1118 | float mv = m.getValuef(); |
| 1119 | int i = 0; |
| 1120 | for (Strip strip : model.strips) { |
| 1121 | for (LXPoint p : strip.points) { |
| 1122 | colors[p.index] = lx.hsb( |
| 1123 | (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360, |
| 1124 | min(100, abs(p.y-sv)), |
| 1125 | max(0, 100 - 50*abs((i%NUM) - mv)) |
| 1126 | ); |
| 1127 | } |
| 1128 | ++i; |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | class AskewPlanes extends SCPattern { |
| 1134 | |
| 1135 | class Plane { |
| 1136 | private final SinLFO a; |
| 1137 | private final SinLFO b; |
| 1138 | private final SinLFO c; |
| 1139 | float av = 1; |
| 1140 | float bv = 1; |
| 1141 | float cv = 1; |
| 1142 | float denom = 0.1; |
| 1143 | |
| 1144 | Plane(int i) { |
| 1145 | addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger(); |
| 1146 | addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger(); |
| 1147 | addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger(); |
| 1148 | } |
| 1149 | |
| 1150 | void run(double deltaMs) { |
| 1151 | av = a.getValuef(); |
| 1152 | bv = b.getValuef(); |
| 1153 | cv = c.getValuef(); |
| 1154 | denom = sqrt(av*av + bv*bv); |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | final Plane[] planes; |
| 1159 | final int NUM_PLANES = 3; |
| 1160 | |
| 1161 | AskewPlanes(LX lx) { |
| 1162 | super(lx); |
| 1163 | planes = new Plane[NUM_PLANES]; |
| 1164 | for (int i = 0; i < planes.length; ++i) { |
| 1165 | planes[i] = new Plane(i); |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | public void run(double deltaMs) { |
| 1170 | float huev = lx.getBaseHuef(); |
| 1171 | |
| 1172 | // This is super fucking bizarre. But if this is a for loop, the framerate |
| 1173 | // tanks to like 30FPS, instead of 60. Call them manually and it works fine. |
| 1174 | // Doesn't make ANY sense... there must be some weird side effect going on |
| 1175 | // with the Processing internals perhaps? |
| 1176 | // for (Plane plane : planes) { |
| 1177 | // plane.run(deltaMs); |
| 1178 | // } |
| 1179 | planes[0].run(deltaMs); |
| 1180 | planes[1].run(deltaMs); |
| 1181 | planes[2].run(deltaMs); |
| 1182 | |
| 1183 | for (LXPoint p : model.points) { |
| 1184 | float d = MAX_FLOAT; |
| 1185 | for (Plane plane : planes) { |
| 1186 | if (plane.denom != 0) { |
| 1187 | d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom); |
| 1188 | } |
| 1189 | } |
| 1190 | colors[p.index] = lx.hsb( |
| 1191 | (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360, |
| 1192 | max(0, 100 - .8*abs(p.x - model.cx)), |
| 1193 | constrain(140 - 10.*d, 0, 100) |
| 1194 | ); |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | class ShiftingPlane extends SCPattern { |
| 1200 | |
| 1201 | final SinLFO a = new SinLFO(-.2, .2, 5300); |
| 1202 | final SinLFO b = new SinLFO(1, -1, 13300); |
| 1203 | final SinLFO c = new SinLFO(-1.4, 1.4, 5700); |
| 1204 | final SinLFO d = new SinLFO(-10, 10, 9500); |
| 1205 | |
| 1206 | ShiftingPlane(LX lx) { |
| 1207 | super(lx); |
| 1208 | addModulator(a).trigger(); |
| 1209 | addModulator(b).trigger(); |
| 1210 | addModulator(c).trigger(); |
| 1211 | addModulator(d).trigger(); |
| 1212 | } |
| 1213 | |
| 1214 | public void run(double deltaMs) { |
| 1215 | float hv = lx.getBaseHuef(); |
| 1216 | float av = a.getValuef(); |
| 1217 | float bv = b.getValuef(); |
| 1218 | float cv = c.getValuef(); |
| 1219 | float dv = d.getValuef(); |
| 1220 | float denom = sqrt(av*av + bv*bv + cv*cv); |
| 1221 | for (LXPoint p : model.points) { |
| 1222 | float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom; |
| 1223 | colors[p.index] = lx.hsb( |
| 1224 | (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360, |
| 1225 | constrain(110 - d*6, 0, 100), |
| 1226 | constrain(130 - 7*d, 0, 100) |
| 1227 | ); |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | class Traktor extends SCPattern { |
| 1233 | |
| 1234 | final int FRAME_WIDTH = 60; |
| 1235 | |
| 1236 | final BasicParameter speed = new BasicParameter("SPD", 0.5); |
| 1237 | |
| 1238 | private float[] bass = new float[FRAME_WIDTH]; |
| 1239 | private float[] treble = new float[FRAME_WIDTH]; |
| 1240 | |
| 1241 | private int index = 0; |
| 1242 | private GraphicEQ eq = null; |
| 1243 | |
| 1244 | public Traktor(LX lx) { |
| 1245 | super(lx); |
| 1246 | for (int i = 0; i < FRAME_WIDTH; ++i) { |
| 1247 | bass[i] = 0; |
| 1248 | treble[i] = 0; |
| 1249 | } |
| 1250 | addParameter(speed); |
| 1251 | } |
| 1252 | |
| 1253 | public void onActive() { |
| 1254 | if (eq == null) { |
| 1255 | eq = new GraphicEQ(lx, 16); |
| 1256 | eq.slope.setValue(0.6); |
| 1257 | eq.level.setValue(0.65); |
| 1258 | eq.range.setValue(0.35); |
| 1259 | eq.release.setValue(0.4); |
| 1260 | addParameter(eq.level); |
| 1261 | addParameter(eq.range); |
| 1262 | addParameter(eq.attack); |
| 1263 | addParameter(eq.release); |
| 1264 | addParameter(eq.slope); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | int counter = 0; |
| 1269 | |
| 1270 | public void run(double deltaMs) { |
| 1271 | eq.run(deltaMs); |
| 1272 | |
| 1273 | int stepThresh = (int) (40 - 39*speed.getValuef()); |
| 1274 | counter += deltaMs; |
| 1275 | if (counter < stepThresh) { |
| 1276 | return; |
| 1277 | } |
| 1278 | counter = counter % stepThresh; |
| 1279 | |
| 1280 | index = (index + 1) % FRAME_WIDTH; |
| 1281 | |
| 1282 | float rawBass = eq.getAverageLevel(0, 4); |
| 1283 | float rawTreble = eq.getAverageLevel(eq.numBands-7, 7); |
| 1284 | |
| 1285 | bass[index] = rawBass * rawBass * rawBass * rawBass; |
| 1286 | treble[index] = rawTreble * rawTreble; |
| 1287 | |
| 1288 | for (LXPoint p : model.points) { |
| 1289 | int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1); |
| 1290 | int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH; |
| 1291 | |
| 1292 | colors[p.index] = lx.hsb( |
| 1293 | (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360, |
| 1294 | 100, |
| 1295 | constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100) |
| 1296 | ); |
| 1297 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
| 1298 | (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360, |
| 1299 | 60, |
| 1300 | constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100) |
| 1301 | |
| 1302 | ), ADD); |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | class ColorFuckerEffect extends LXEffect { |
| 1308 | |
| 1309 | final BasicParameter level = new BasicParameter("BRT", 1); |
| 1310 | final BasicParameter desat = new BasicParameter("DSAT", 0); |
| 1311 | final BasicParameter hueShift = new BasicParameter("HSHFT", 0); |
| 1312 | final BasicParameter sharp = new BasicParameter("SHARP", 0); |
| 1313 | final BasicParameter soft = new BasicParameter("SOFT", 0); |
| 1314 | final BasicParameter mono = new BasicParameter("MONO", 0); |
| 1315 | final BasicParameter invert = new BasicParameter("INVERT", 0); |
| 1316 | |
| 1317 | |
| 1318 | float[] hsb = new float[3]; |
| 1319 | |
| 1320 | ColorFuckerEffect(LX lx) { |
| 1321 | super(lx); |
| 1322 | addParameter(level); |
| 1323 | addParameter(desat); |
| 1324 | addParameter(sharp); |
| 1325 | addParameter(hueShift); |
| 1326 | addParameter(soft); |
| 1327 | addParameter(mono); |
| 1328 | addParameter(invert); |
| 1329 | } |
| 1330 | |
| 1331 | public void apply(int[] colors) { |
| 1332 | if (!isEnabled()) { |
| 1333 | return; |
| 1334 | } |
| 1335 | float bMod = level.getValuef(); |
| 1336 | float sMod = 1 - desat.getValuef(); |
| 1337 | float hMod = hueShift.getValuef(); |
| 1338 | float fSharp = sharp.getValuef(); |
| 1339 | float fSoft = soft.getValuef(); |
| 1340 | boolean mon = mono.getValuef() > 0.5; |
| 1341 | boolean ivt = invert.getValuef() > 0.5; |
| 1342 | if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) { |
| 1343 | for (int i = 0; i < colors.length; ++i) { |
| 1344 | lx.RGBtoHSB(colors[i], hsb); |
| 1345 | if (mon) { |
| 1346 | hsb[0] = lx.getBaseHuef() / 360.; |
| 1347 | } |
| 1348 | if (ivt) { |
| 1349 | hsb[2] = 1 - hsb[2]; |
| 1350 | } |
| 1351 | if (fSharp > 0) { |
| 1352 | fSharp = 1/(1-fSharp); |
| 1353 | if (hsb[2] < .5) { |
| 1354 | hsb[2] = pow(hsb[2],fSharp); |
| 1355 | } else { |
| 1356 | hsb[2] = 1-pow(1-hsb[2],fSharp); |
| 1357 | } |
| 1358 | } |
| 1359 | if (fSoft > 0) { |
| 1360 | if (hsb[2] > 0.5) { |
| 1361 | hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft); |
| 1362 | } else { |
| 1363 | hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft); |
| 1364 | } |
| 1365 | } |
| 1366 | colors[i] = lx.hsb( |
| 1367 | (360. * hsb[0] + hMod*360.) % 360, |
| 1368 | 100. * hsb[1] * sMod, |
| 1369 | 100. * hsb[2] * bMod |
| 1370 | ); |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | class QuantizeEffect extends LXEffect { |
| 1377 | |
| 1378 | color[] quantizedFrame; |
| 1379 | float lastQuant; |
| 1380 | final BasicParameter amount = new BasicParameter("AMT", 0); |
| 1381 | |
| 1382 | QuantizeEffect(LX lx) { |
| 1383 | super(lx); |
| 1384 | quantizedFrame = new color[lx.total]; |
| 1385 | lastQuant = 0; |
| 1386 | } |
| 1387 | |
| 1388 | public void apply(int[] colors) { |
| 1389 | float fQuant = amount.getValuef(); |
| 1390 | if (fQuant > 0) { |
| 1391 | float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4)))); |
| 1392 | float f = lastQuant; |
| 1393 | lastQuant = tRamp; |
| 1394 | if (tRamp > f) { |
| 1395 | for (int i = 0; i < colors.length; ++i) { |
| 1396 | colors[i] = quantizedFrame[i]; |
| 1397 | } |
| 1398 | return; |
| 1399 | } |
| 1400 | } |
| 1401 | for (int i = 0; i < colors.length; ++i) { |
| 1402 | quantizedFrame[i] = colors[i]; |
| 1403 | } |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | class BlurEffect extends LXEffect { |
| 1408 | |
| 1409 | final BasicParameter amount = new BasicParameter("AMT", 0); |
| 1410 | final int[] frame; |
| 1411 | final LinearEnvelope env = new LinearEnvelope(0, 1, 100); |
| 1412 | |
| 1413 | BlurEffect(LX lx) { |
| 1414 | super(lx); |
| 1415 | addParameter(amount); |
| 1416 | addModulator(env); |
| 1417 | frame = new int[lx.total]; |
| 1418 | for (int i = 0; i < frame.length; ++i) { |
| 1419 | frame[i] = #000000; |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | public void onEnable() { |
| 1424 | env.setRangeFromHereTo(1, 400).start(); |
| 1425 | for (int i = 0; i < frame.length; ++i) { |
| 1426 | frame[i] = #000000; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | public void onDisable() { |
| 1431 | env.setRangeFromHereTo(0, 1000).start(); |
| 1432 | } |
| 1433 | |
| 1434 | public void apply(int[] colors) { |
| 1435 | float amt = env.getValuef() * amount.getValuef(); |
| 1436 | if (amt > 0) { |
| 1437 | amt = (1 - amt); |
| 1438 | amt = 1 - (amt*amt*amt); |
| 1439 | for (int i = 0; i < colors.length; ++i) { |
| 1440 | // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN); |
| 1441 | frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB); |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | } |
| 1446 | } |
| 1447 | |