class Amoeba extends ParticleWrapper2D { Particle[] arms; color baseColor; int myNote; int myVel; float currAlpha; float targAlpha; Amoeba(ParticleSystem ps, Particle p, int note, int vel) { super(p); arms = new Particle[10]; float inc = TWO_PI / arms.length; for(int i = 0; i < arms.length; i++) { float x = x() + 10*sin(inc*i); float y = y() + 10*cos(inc*i); arms[i] = ps.makeParticle(1, x, y, 0); float len = random(10, 12); ps.makeSpring(p, arms[i], 0.2, 0.1, len); } for(int i = 0; i < arms.length; i++) { Particle p1 = arms[i]; Particle p2 = arms[ (i+1) % arms.length ]; float len= random(2, 3); ps.makeSpring(p1, p2, 0.2, 0.1, len); } myNote = note; myVel = vel; float h = map(note, 0, 127, 100, 110); float s = map(vel, 64, 127, 128, 255); baseColor = color(h, s, 255); currAlpha = 0; targAlpha = 255; } void update() { float sc = 1.5; //addVelocity(random(-sc, sc), random(-sc, sc)); int a = int(random(0, arms.length -1)); float asc = 1; arms[a].addVelocity(random(-asc, asc), random(-asc, asc), 0); float edgeBounce = 2; if ( x() < 10 ) { addVelocity(edgeBounce, 0); } else if ( x() > width - 10 ) { addVelocity(-edgeBounce, 0); } if ( y() < 10 ) { addVelocity(0, edgeBounce); } else if ( y() > height - 10 ) { addVelocity(0, -edgeBounce); } // alpha update float ainc = 5; float amin = 64; if ( currAlpha <= targAlpha ) { currAlpha += ainc; if ( currAlpha > targAlpha ) { targAlpha = random(amin, amin + 30); } } else if ( currAlpha >= targAlpha ) { currAlpha -= ainc; if ( currAlpha < targAlpha ) { targAlpha = random(235, 255); } } } void addVelocity(float x, float y) { super.addVelocity(x, y); for(int i = 0; i < arms.length; i++) { arms[i].addVelocity(x, y, 0); } } void draw() { stroke(baseColor, currAlpha); noFill(); beginShape(); curveVertex(arms[0].position().x(), arms[0].position().y()); for(int i = 0; i < arms.length; i++) { curveVertex(arms[i].position().x(), arms[i].position().y()); Particle p1 = arms[i]; Particle p2 = arms[ (i+1) % arms.length ]; float xmid = p1.position().x() + ( p2.position().x() - p1.position().x() ) / 2; float ymid = p1.position().y() + ( p2.position().y() - p1.position().y() ) / 2; curveVertex(xmid, ymid); } curveVertex(arms[0].position().x(), arms[0].position().y()); curveVertex(arms[1].position().x(), arms[1].position().y()); endShape(); } }