/* * Follows the mouse around to get a better look. * You can poke his eyes. * Ryan Janzen * lagattack (at) gmail.com * Uses traer physics library. */ import traer.physics.*; ParticleSystem ps; Eye [] eyes; Stalk [] stalks; Attraction [][] repulsionBetweenEyes; Body b; Particle mouseTarget; // lower this if too slow final int numEyes = 8; void setup() { size(800, 600); frameRate(24); ps = new ParticleSystem(0, 0.1); mouseTarget = ps.makeParticle(10,width/2,height/2,0); mouseTarget.makeFixed(); // create body Particle bp = ps.makeParticle(1.0, width/2, height/2, 0); b = new Body(bp, width/4, height/4); createEyes(mouseTarget); createEyesRepulsion(eyes); createStalks(bp, eyes); } void draw() { mouseTarget.moveTo(mouseX, mouseY, 0); background(255); // draw stalks for(int i = 0; i < stalks.length; i++) { stalks[i].draw(); } // draw body b.draw(); // update and draw eyes for(int i = 0; i < eyes.length; i++) { Eye e = eyes[i]; // turn on or off inter-eye repulsion if(e.cooldown > 0) { for(int j = 0; j < repulsionBetweenEyes[i].length; j++) { if(i != j) { // no attraction to itself repulsionBetweenEyes[i][j].turnOff(); } } } else { for(int j = 0; j < repulsionBetweenEyes[i].length; j++) { if(i != j) { // no attraction to itself repulsionBetweenEyes[i][j].turnOn(); } } } e.update(); e.draw(); } // update particle system ps.tick(); } void createEyes(Particle mouseTarget) { eyes = new Eye[numEyes]; for(int i = 0; i < eyes.length; i++) { Particle location = ps.makeParticle(10, random(width), random(height), 0); Spring s = ps.makeSpring(location, mouseTarget, 5, 0.5, 0.01); eyes[i] = new Eye(location, mouseTarget, s); } } void createStalks(Particle body, Eye [] eyes) { stalks = new Stalk[numEyes]; for(int i = 0; i < stalks.length; i++) { stalks[i] = new Stalk(body, eyes[i].location, ps); } } void createEyesRepulsion(Eye [] eyes) { repulsionBetweenEyes = new Attraction[eyes.length][eyes.length]; for(int i = 0; i < eyes.length; i++) { Particle p0 = eyes[i].location; for(int j = 0; j < eyes.length; j++) { Particle p1 = eyes[j].location; // no attraction to itself if(i != j) { repulsionBetweenEyes[i][j] = ps.makeAttraction(p0, p1, -10, 0.1); } } } }