| 1 | class BouncyBalls extends SCPattern { |
| 2 | |
| 3 | static final int NUM_BALLS = 6; |
| 4 | |
| 5 | class BouncyBall { |
| 6 | |
| 7 | Accelerator yPos; |
| 8 | TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000)); |
| 9 | float zPos; |
| 10 | |
| 11 | BouncyBall(int i) { |
| 12 | addModulator(xPos).setBasis(random(0, TWO_PI)).start(); |
| 13 | addModulator(yPos = new Accelerator(0, 0, 0)); |
| 14 | zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.)); |
| 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); |
| 38 | float xv = xPos.getValuef(); |
| 39 | float yv = yPos.getValuef(); |
| 40 | |
| 41 | for (Point p : model.points) { |
| 42 | float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos)); |
| 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 | |
| 55 | final BouncyBall[] balls = new BouncyBall[NUM_BALLS]; |
| 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 | |
| 61 | BouncyBalls(GLucose glucose) { |
| 62 | super(glucose); |
| 63 | for (int i = 0; i < balls.length; ++i) { |
| 64 | balls[i] = new BouncyBall(i); |
| 65 | } |
| 66 | addParameter(bounce); |
| 67 | addParameter(flr); |
| 68 | addParameter(blobSize); |
| 69 | } |
| 70 | |
| 71 | public void run(double deltaMs) { |
| 72 | setColors(#000000); |
| 73 | for (BouncyBall b : balls) { |
| 74 | b.run(deltaMs); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public boolean noteOnReceived(Note note) { |
| 79 | int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS; |
| 80 | balls[pitch].bounce(note.getVelocity()); |
| 81 | return true; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | class SpaceTime extends SCPattern { |
| 86 | |
| 87 | SinLFO pos = new SinLFO(0, 1, 3000); |
| 88 | SinLFO rate = new SinLFO(1000, 9000, 13000); |
| 89 | SinLFO falloff = new SinLFO(10, 70, 5000); |
| 90 | float angle = 0; |
| 91 | |
| 92 | BasicParameter rateParameter = new BasicParameter("RATE", 0.5); |
| 93 | BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5); |
| 94 | |
| 95 | |
| 96 | public SpaceTime(GLucose glucose) { |
| 97 | super(glucose); |
| 98 | |
| 99 | addModulator(pos).trigger(); |
| 100 | addModulator(rate).trigger(); |
| 101 | addModulator(falloff).trigger(); |
| 102 | pos.modulateDurationBy(rate); |
| 103 | addParameter(rateParameter); |
| 104 | addParameter(sizeParameter); |
| 105 | } |
| 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()); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | void run(double deltaMs) { |
| 116 | angle += deltaMs * 0.0007; |
| 117 | float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle)); |
| 118 | float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle)); |
| 119 | |
| 120 | float pVal = pos.getValuef(); |
| 121 | float fVal = falloff.getValuef(); |
| 122 | |
| 123 | int s = 0; |
| 124 | for (Strip strip : model.strips) { |
| 125 | int i = 0; |
| 126 | for (Point p : strip.points) { |
| 127 | colors[p.index] = color( |
| 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 | ); |
| 132 | ++i; |
| 133 | } |
| 134 | ++s; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | class Swarm extends SCPattern { |
| 140 | |
| 141 | SawLFO offset = new SawLFO(0, 1, 1000); |
| 142 | SinLFO rate = new SinLFO(350, 1200, 63000); |
| 143 | SinLFO falloff = new SinLFO(15, 50, 17000); |
| 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); |
| 147 | |
| 148 | public Swarm(GLucose glucose) { |
| 149 | super(glucose); |
| 150 | |
| 151 | addModulator(offset).trigger(); |
| 152 | addModulator(rate).trigger(); |
| 153 | addModulator(falloff).trigger(); |
| 154 | addModulator(fX).trigger(); |
| 155 | addModulator(fY).trigger(); |
| 156 | addModulator(hOffX).trigger(); |
| 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 | |
| 171 | void run(double deltaMs) { |
| 172 | float s = 0; |
| 173 | for (Strip strip : model.strips ) { |
| 174 | int i = 0; |
| 175 | for (Point p : strip.points) { |
| 176 | float fV = max(-1, 1 - dist(p.fx/2., p.fy, fX.getValuef()/2., fY.getValuef()) / 64.); |
| 177 | colors[p.index] = color( |
| 178 | (lx.getBaseHuef() + 0.3 * abs(p.fx - hOffX.getValuef())) % 360, |
| 179 | constrain(80 + 40 * fV, 0, 100), |
| 180 | constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100) |
| 181 | ); |
| 182 | ++i; |
| 183 | } |
| 184 | ++s; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | class SwipeTransition extends SCTransition { |
| 190 | |
| 191 | final BasicParameter bleed = new BasicParameter("WIDTH", 0.5); |
| 192 | |
| 193 | SwipeTransition(GLucose glucose) { |
| 194 | super(glucose); |
| 195 | setDuration(5000); |
| 196 | addParameter(bleed); |
| 197 | } |
| 198 | |
| 199 | void computeBlend(int[] c1, int[] c2, double progress) { |
| 200 | float bleedf = 10 + bleed.getValuef() * 200.; |
| 201 | float xPos = (float) (-bleedf + progress * (model.xMax + bleedf)); |
| 202 | for (Point p : model.points) { |
| 203 | float d = (p.fx - xPos) / bleedf; |
| 204 | if (d < 0) { |
| 205 | colors[p.index] = c2[p.index]; |
| 206 | } else if (d > 1) { |
| 207 | colors[p.index] = c1[p.index]; |
| 208 | } else { |
| 209 | colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | abstract class BlendTransition extends SCTransition { |
| 216 | |
| 217 | final int blendType; |
| 218 | |
| 219 | BlendTransition(GLucose glucose, int blendType) { |
| 220 | super(glucose); |
| 221 | this.blendType = blendType; |
| 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], |
| 229 | blendColor(c1[i], c2[i], blendType), |
| 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], |
| 237 | blendColor(c1[i], c2[i], blendType), |
| 238 | (float) (2.*(1. - progress)), |
| 239 | RGB); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | class MultiplyTransition extends BlendTransition { |
| 246 | MultiplyTransition(GLucose glucose) { |
| 247 | super(glucose, MULTIPLY); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | class ScreenTransition extends BlendTransition { |
| 252 | ScreenTransition(GLucose glucose) { |
| 253 | super(glucose, SCREEN); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | class BurnTransition extends BlendTransition { |
| 258 | BurnTransition(GLucose glucose) { |
| 259 | super(glucose, BURN); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | class DodgeTransition extends BlendTransition { |
| 264 | DodgeTransition(GLucose glucose) { |
| 265 | super(glucose, DODGE); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | class OverlayTransition extends BlendTransition { |
| 270 | OverlayTransition(GLucose glucose) { |
| 271 | super(glucose, OVERLAY); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | class AddTransition extends BlendTransition { |
| 276 | AddTransition(GLucose glucose) { |
| 277 | super(glucose, ADD); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | class SubtractTransition extends BlendTransition { |
| 282 | SubtractTransition(GLucose glucose) { |
| 283 | super(glucose, SUBTRACT); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | class SoftLightTransition extends BlendTransition { |
| 288 | SoftLightTransition(GLucose glucose) { |
| 289 | super(glucose, SOFT_LIGHT); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | class 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 | |
| 313 | public void run(double deltaMs) { |
| 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 | |
| 337 | class CubeEQ extends SCPattern { |
| 338 | |
| 339 | private GraphicEQ eq = null; |
| 340 | |
| 341 | private final BasicParameter edge = new BasicParameter("EDGE", 0.5); |
| 342 | private final BasicParameter clr = new BasicParameter("CLR", 0.5); |
| 343 | private final BasicParameter blockiness = new BasicParameter("BLK", 0.5); |
| 344 | |
| 345 | public CubeEQ(GLucose glucose) { |
| 346 | super(glucose); |
| 347 | } |
| 348 | |
| 349 | protected void onActive() { |
| 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); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | public void run(double deltaMs) { |
| 364 | eq.run(deltaMs); |
| 365 | |
| 366 | float edgeConst = 2 + 30*edge.getValuef(); |
| 367 | float clrConst = 1.1 + clr.getValuef(); |
| 368 | |
| 369 | for (Point p : model.points) { |
| 370 | float avgIndex = constrain(2 + p.fx / model.xMax * (eq.numBands-4), 0, eq.numBands-4); |
| 371 | int avgFloor = (int) avgIndex; |
| 372 | |
| 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); |
| 387 | colors[p.index] = color( |
| 388 | (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360, |
| 389 | 100, |
| 390 | b |
| 391 | ); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | class 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>(); |
| 403 | final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10; |
| 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(); |
| 415 | boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300); |
| 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(); |
| 424 | for (Point p : model.points) { |
| 425 | colors[p.index] = blendColor( |
| 426 | colors[p.index], |
| 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)), |
| 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 | } |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | public 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); |
| 478 | |
| 479 | addParameter(attack); |
| 480 | addParameter(release); |
| 481 | addParameter(level); |
| 482 | cubeBrt = new LinearEnvelope[model.cubes.size() / 4]; |
| 483 | for (int i = 0; i < cubeBrt.length; ++i) { |
| 484 | addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100)); |
| 485 | } |
| 486 | base = new SinLFO[model.cubes.size() / 12]; |
| 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 | |
| 508 | public boolean noteOnReceived(Note note) { |
| 509 | LinearEnvelope env = getEnvelope(note.getPitch()); |
| 510 | env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start(); |
| 511 | return true; |
| 512 | } |
| 513 | |
| 514 | public boolean noteOffReceived(Note note) { |
| 515 | getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start(); |
| 516 | return true; |
| 517 | } |
| 518 | |
| 519 | public void run(double deltaMs) { |
| 520 | int i = 0; |
| 521 | float huef = lx.getBaseHuef(); |
| 522 | float levelf = level.getValuef(); |
| 523 | for (Cube c : model.cubes) { |
| 524 | float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef()); |
| 525 | setColor(c, color( |
| 526 | (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360, |
| 527 | min(100, 120*v), |
| 528 | 100*v |
| 529 | )); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | class CrossSections extends SCPattern { |
| 535 | |
| 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); |
| 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); |
| 543 | final BasicParameter xr = new BasicParameter("XRAT", 0.7); |
| 544 | final BasicParameter yr = new BasicParameter("YRAT", 0.6); |
| 545 | final BasicParameter zr = new BasicParameter("ZRAT", 0.5); |
| 546 | final BasicParameter xl = new BasicParameter("XLEV", 1); |
| 547 | final BasicParameter yl = new BasicParameter("YLEV", 1); |
| 548 | final BasicParameter zl = new BasicParameter("ZLEV", 0.5); |
| 549 | |
| 550 | |
| 551 | CrossSections(GLucose glucose) { |
| 552 | super(glucose); |
| 553 | addModulator(x).trigger(); |
| 554 | addModulator(y).trigger(); |
| 555 | addModulator(z).trigger(); |
| 556 | addParams(); |
| 557 | } |
| 558 | |
| 559 | protected void addParams() { |
| 560 | addParameter(xr); |
| 561 | addParameter(yr); |
| 562 | addParameter(zr); |
| 563 | addParameter(xw); |
| 564 | addParameter(xl); |
| 565 | addParameter(yl); |
| 566 | addParameter(zl); |
| 567 | addParameter(yw); |
| 568 | addParameter(zw); |
| 569 | } |
| 570 | |
| 571 | void onParameterChanged(LXParameter p) { |
| 572 | if (p == xr) { |
| 573 | x.setDuration(10000 - 8800*p.getValuef()); |
| 574 | } else if (p == yr) { |
| 575 | y.setDuration(10000 - 9000*p.getValuef()); |
| 576 | } else if (p == zr) { |
| 577 | z.setDuration(10000 - 9000*p.getValuef()); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | float xv, yv, zv; |
| 582 | |
| 583 | protected void updateXYZVals() { |
| 584 | xv = x.getValuef(); |
| 585 | yv = y.getValuef(); |
| 586 | zv = z.getValuef(); |
| 587 | } |
| 588 | |
| 589 | public void run(double deltaMs) { |
| 590 | updateXYZVals(); |
| 591 | |
| 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 | |
| 600 | for (Point p : model.points) { |
| 601 | color c = 0; |
| 602 | c = blendColor(c, color( |
| 603 | (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360, |
| 604 | constrain(140 - 1.1*abs(p.fx - model.xMax/2.), 0, 100), |
| 605 | max(0, xlv - xwv*abs(p.fx - xv)) |
| 606 | ), ADD); |
| 607 | c = blendColor(c, color( |
| 608 | (lx.getBaseHuef() + 80 + p.fy/10) % 360, |
| 609 | constrain(140 - 2.2*abs(p.fy - model.yMax/2.), 0, 100), |
| 610 | max(0, ylv - ywv*abs(p.fy - yv)) |
| 611 | ), ADD); |
| 612 | c = blendColor(c, color( |
| 613 | (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360, |
| 614 | constrain(140 - 2.2*abs(p.fz - model.zMax/2.), 0, 100), |
| 615 | max(0, zlv - zwv*abs(p.fz - zv)) |
| 616 | ), ADD); |
| 617 | colors[p.index] = c; |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | class Blinders extends SCPattern { |
| 623 | |
| 624 | final SinLFO[] m; |
| 625 | final TriangleLFO r; |
| 626 | final SinLFO s; |
| 627 | final TriangleLFO hs; |
| 628 | |
| 629 | public Blinders(GLucose glucose) { |
| 630 | super(glucose); |
| 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(); |
| 637 | addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger(); |
| 638 | s.modulateDurationBy(r); |
| 639 | } |
| 640 | |
| 641 | public void run(double deltaMs) { |
| 642 | float hv = lx.getBaseHuef(); |
| 643 | int si = 0; |
| 644 | for (Strip strip : model.strips) { |
| 645 | int i = 0; |
| 646 | float mv = m[si % m.length].getValuef(); |
| 647 | for (Point p : strip.points) { |
| 648 | colors[p.index] = color( |
| 649 | (hv + p.fz + p.fy*hs.getValuef()) % 360, |
| 650 | min(100, abs(p.fx - s.getValuef())/2.), |
| 651 | max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.)) |
| 652 | ); |
| 653 | ++i; |
| 654 | } |
| 655 | ++si; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | class 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 | } |
| 675 | |
| 676 | void run(double deltaMs) { |
| 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 | } |
| 694 | |
| 695 | class AskewPlanes extends SCPattern { |
| 696 | |
| 697 | class Plane { |
| 698 | private final SinLFO a; |
| 699 | private final SinLFO b; |
| 700 | private final SinLFO c; |
| 701 | float av = 1; |
| 702 | float bv = 1; |
| 703 | float cv = 1; |
| 704 | float denom = 0.1; |
| 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 | |
| 712 | void run(double deltaMs) { |
| 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 | } |
| 730 | |
| 731 | public void run(double deltaMs) { |
| 732 | float huev = lx.getBaseHuef(); |
| 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 | |
| 745 | for (Point p : model.points) { |
| 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 | ); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | class 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 | |
| 776 | public void run(double deltaMs) { |
| 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) { |
| 784 | float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom; |
| 785 | colors[p.index] = color( |
| 786 | (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360, |
| 787 | constrain(110 - d*6, 0, 100), |
| 788 | constrain(130 - 7*d, 0, 100) |
| 789 | ); |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | class 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 | |
| 832 | public void run(double deltaMs) { |
| 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 | } |
| 868 | |
| 869 | class 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) { |
| 883 | if (!enabled) { |
| 884 | return; |
| 885 | } |
| 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 | } |
| 900 | |
| 901 | class 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 | } |