import traer.physics.*; // Schooling/Flocking behaviour based on Craig Reynolds' // Boids rules - implemented with the Traer Physics Library ParticleSystem sys; ArrayList particles; ArrayList springs; void setup() { size(600,600); background(255); smooth(); strokeWeight(2); fill(0xbf,0xff,0xff,50); sys = new ParticleSystem(0,0.001); particles = new ArrayList(); springs = new ArrayList(); // Generate randomly positioned particles for (int i=0; i<40; i++) particles.add(sys.makeParticle(1.0,random(width),random(height),random(width))); // This double loops attaches every particle to // every other particle using both an Attraction // and a Spring. for (int i=0; i height) { p.moveTo(p.position().x(), height, p.position().z()); p.setVelocity(p.velocity().x(), p.velocity().y()*-1, p.velocity().z()); } if (p.position().y() < 0) { p.moveTo(p.position().x(), 0, p.position().z()); p.setVelocity(p.velocity().x(), p.velocity().y()*-1, p.velocity().z()); } if (p.position().x() > width) { p.moveTo(width, p.position().y(), p.position().z()); p.setVelocity(p.velocity().x()*-1, p.velocity().y(), p.velocity().z()); } if (p.position().x() < 0) { p.moveTo(0, p.position().y(), p.position().z()); p.setVelocity(p.velocity().x()*-1, p.velocity().y(), p.velocity().z()); } if (p.position().z() > width) { p.moveTo(p.position().x(), p.position().y(), width); p.setVelocity(p.velocity().x(), p.velocity().y(), p.velocity().z()*-1); } if (p.position().z() < 0) { p.moveTo(p.position().x(), p.position().y(), 0); p.setVelocity(p.velocity().x(), p.velocity().y(), p.velocity().z()*-1); } } // use this instead of detectCollisions if "pacman" world is wanted void loopAtBoundary(Particle p) { if (p.position().y() > height) { p.moveTo(p.position().x(), 0, p.position().z()); } if (p.position().y() < 0) { p.moveTo(p.position().x(), height, p.position().z()); } if (p.position().x() > width) { p.moveTo(0, p.position().y(), p.position().z()); } if (p.position().x() < 0) { p.moveTo(width, p.position().y(), p.position().z()); } } // Steers current particle towards heading of nearby particles void rule3() { for (int i=0; i limit) p.setVelocity(p.velocity().x()*0.8,p.velocity().y(),p.velocity().z()); if (abs(p.velocity().y()) > limit) p.setVelocity(p.velocity().x(),p.velocity().y()*0.8,p.velocity().z()); if (abs(p.velocity().z()) > limit) p.setVelocity(p.velocity().x(),p.velocity().y(),p.velocity().z()*0.8); } } // For screenshots void keyPressed() { if(key == 's' || key == 'S') { save("capture.tif"); } }