class Stalk { Particle start; Particle end; Particle [] links; final int numLinks = 7; Stalk(Particle s, Particle e, ParticleSystem ps) { start = s; end = e; links = new Particle[numLinks]; createSprings(s, e, links, ps); } void draw() { stroke(0); strokeWeight(3); noFill(); // draw line between each link beginShape(); vertex(start.position().x(), start.position().y()); for(int i = 0 ; i < links.length; i++) { Particle p = links[i]; vertex(p.position().x(), p.position().y()); } vertex(end.position().x(), end.position().y()); endShape(); } void createSprings(Particle s, Particle e, Particle [] ls, ParticleSystem ps) { // create along line between s and e to minimize entropy float dx = s.position().x() - e.position().y(); float dy = s.position().y() - e.position().x(); float stepX = dx / ls.length; float stepY = dy / ls.length; float x = s.position().x(); float y = s.position().y(); Particle lp = s; for(int i = 0; i < ls.length; i++) { Particle p = ps.makeParticle(1.0, x, y, 0); ls[i] = p; createSpring(p, lp, ps); lp = p; x += stepX; y += stepY; } createSpring(lp, e, ps); } void createSpring(Particle p0, Particle p1, ParticleSystem ps) { ps.makeSpring(p0, p1, 0.3, 0.4, 5); } }