Particle Systems in Processing    
     
09.27.04

<  ^  >

Adding a spring

 

A spring is our second type of force (after gravity)

its force is proportional to its stretch

  • it has a rest-length
  • a strength
  • and a damping

 

Example 4

  • adding springs

 

PSystem ps;

void setup() {
  size(500,500);
  ps = (PSystem)loadPlugin("PSystem");
  
  Particle p1 = new Particle();
  p1.setPos(width / 2 - 10, height/2, 0);
  p1.fix();
  
  Particle p2 = new Particle();
  p2.setPos(width / 2 + 10, height/2, 0);
  
  ps.addParticle(p1);
  ps.addParticle(p2);
  
  ps.addSpring(p1, p2);
  
  ps.setGravity(0.5);

}

void loop() {
  background(#99CCCC);
  ps.draw();
}