// Patrick Grizzard // Nature of Code // Spring 2010 // Adapted from toxiclibs' softbody square example import toxi.physics.*; import toxi.geom.*; import processing.opengl.*; VerletPhysics physics; int DIM=30; int REST_LENGTH=20; float STRENGTH=0.1; float INNER_STRENGTH = 0.125; void setup() { size(800,600); smooth(); physics = new VerletPhysics(); physics.setGravity(new Vec3D(0,0.01,0)); // This is the center of the world Vec3D center = new Vec3D(width/2,height/2,0); // These are the world's dimensions Vec3D extent = new Vec3D(width/2,height/2,0); // Set the world's bounding box physics.setWorldBounds(new AABB(center,extent)); // Create a grid of particles and connect with springs for (int y = 0,idx=0; y < DIM; y++) { for(int x = 0; x< DIM; x++) { Particle p=new Particle(x*REST_LENGTH+10,y*REST_LENGTH+10,0,5,5); physics.addParticle(p); if (x>0) { VerletSpring s=new VerletSpring(p,physics.particles.get(idx-1),REST_LENGTH,STRENGTH); physics.addSpring(s); } if (y>0) { VerletSpring s=new VerletSpring(p,physics.particles.get(idx-DIM),REST_LENGTH,STRENGTH); physics.addSpring(s); } idx++; } } // Create internal springs that connect top-left to bottom-right (not drawn) Particle p=(Particle)physics.particles.get(0); Particle q=(Particle)physics.particles.get(physics.particles.size()-1); float len=sqrt(sq(REST_LENGTH*(DIM-1))*2); VerletSpring s=new VerletSpring(p,q,len,INNER_STRENGTH); physics.addSpring(s); // Create internal springs that connect top-right to bottom-left (not drawn) p=(Particle)physics.particles.get(DIM-1); q=(Particle)physics.particles.get(physics.particles.size()-DIM); s=new VerletSpring(p,q,len,INNER_STRENGTH); physics.addSpring(s); // Pin top edge for (int i=0; i