From: Mark Slee Date: Fri, 27 Sep 2013 04:50:11 +0000 (-0700) Subject: Add blank pattern to right deck, clean up bouncyballs X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d1dcc4b55abff7b6efa2816695e29f3fa7ee7fc9;p=SugarCubes.git Add blank pattern to right deck, clean up bouncyballs --- diff --git a/MarkSlee.pde b/MarkSlee.pde index 55f0922..699df38 100644 --- a/MarkSlee.pde +++ b/MarkSlee.pde @@ -1,15 +1,17 @@ -class Flitters extends SCPattern { +class BouncyBalls extends SCPattern { - static final int NUM_FLITTERS = 6; + static final int NUM_BALLS = 6; - class Flitter { + class BouncyBall { Accelerator yPos; TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000)); + float zPos; - Flitter(int i) { + BouncyBall(int i) { addModulator(xPos).setBasis(random(0, TWO_PI)).start(); addModulator(yPos = new Accelerator(0, 0, 0)); + zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.)); } void bounce(float midiVel) { @@ -33,8 +35,11 @@ class Flitters extends SCPattern { } } float falloff = 130.f / (12 + blobSize.getValuef() * 36); + float xv = xPos.getValuef(); + float yv = yPos.getValuef(); + for (Point p : model.points) { - float d = dist(p.x, p.y, xPos.getValuef(), yPos.getValuef()); + float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos)); float b = constrain(130 - falloff*d, 0, 100); if (b > 0) { colors[p.index] = blendColor(colors[p.index], color( @@ -47,16 +52,16 @@ class Flitters extends SCPattern { } } - final Flitter[] flitters = new Flitter[NUM_FLITTERS]; + final BouncyBall[] balls = new BouncyBall[NUM_BALLS]; final BasicParameter bounce = new BasicParameter("BNC", .8); final BasicParameter flr = new BasicParameter("FLR", 0); final BasicParameter blobSize = new BasicParameter("SIZE", 0.5); - Flitters(GLucose glucose) { + BouncyBalls(GLucose glucose) { super(glucose); - for (int i = 0; i < flitters.length; ++i) { - flitters[i] = new Flitter(i); + for (int i = 0; i < balls.length; ++i) { + balls[i] = new BouncyBall(i); } addParameter(bounce); addParameter(flr); @@ -65,14 +70,14 @@ class Flitters extends SCPattern { public void run(double deltaMs) { setColors(#000000); - for (Flitter f : flitters) { - f.run(deltaMs); + for (BouncyBall b : balls) { + b.run(deltaMs); } } public boolean noteOnReceived(Note note) { - int pitch = (note.getPitch() + note.getChannel()) % NUM_FLITTERS; - flitters[pitch].bounce(note.getVelocity()); + int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS; + balls[pitch].bounce(note.getVelocity()); return true; } } diff --git a/SugarCubes.pde b/SugarCubes.pde index ef89237..42817a6 100644 --- a/SugarCubes.pde +++ b/SugarCubes.pde @@ -26,8 +26,8 @@ LXPattern[] patterns(GLucose glucose) { return new LXPattern[] { - // Slee - new Flitters(glucose), + // Slee + new BouncyBalls(glucose), new Swarm(glucose), new SpaceTime(glucose), new ShiftingPlane(glucose), @@ -41,7 +41,7 @@ LXPattern[] patterns(GLucose glucose) { new CubeEQ(glucose).setEligible(false), new PianoKeyPattern(glucose).setEligible(false), - // DanH + // DanH new Noise(glucose), new Play(glucose), new Pong(glucose), diff --git a/TestPatterns.pde b/TestPatterns.pde index f8d59ee..2f04698 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -1,3 +1,13 @@ +class BlankPattern extends SCPattern { + BlankPattern(GLucose glucose) { + super(glucose); + } + + public void run(double deltaMs) { + setColors(#000000); + } +} + abstract class TestPattern extends SCPattern { public TestPattern(GLucose glucose) { super(glucose); diff --git a/_Internals.pde b/_Internals.pde index c86ff96..f25f74a 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -72,14 +72,31 @@ float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ; /** * Engine construction and initialization. */ -LXPattern[] _patterns(GLucose glucose) { + +LXTransition _transition(GLucose glucose) { + return new DissolveTransition(glucose.lx).setDuration(1000); +} + +LXPattern[] _leftPatterns(GLucose glucose) { LXPattern[] patterns = patterns(glucose); for (LXPattern p : patterns) { - p.setTransition(new DissolveTransition(glucose.lx).setDuration(1000)); + p.setTransition(_transition(glucose)); } return patterns; } +LXPattern[] _rightPatterns(GLucose glucose) { + LXPattern[] patterns = _leftPatterns(glucose); + LXPattern[] rightPatterns = new LXPattern[patterns.length+1]; + int i = 0; + rightPatterns[i++] = new BlankPattern(glucose).setTransition(_transition(glucose)); + for (LXPattern p : patterns) { + rightPatterns[i++] = p; + } + return rightPatterns; +} + + void logTime(String evt) { int now = millis(); println(evt + ": " + (now - lastMillis) + "ms"); @@ -108,8 +125,8 @@ void setup() { // Set the patterns Engine engine = lx.engine; - engine.setPatterns(patterns = _patterns(glucose)); - engine.addDeck(_patterns(glucose)); + engine.setPatterns(patterns = _leftPatterns(glucose)); + engine.addDeck(_rightPatterns(glucose)); logTime("Built patterns"); glucose.setTransitions(transitions(glucose)); logTime("Built transitions");