/* cut'n'pasting from traer examples... wwww.pixelorchestra.com */ import traer.physics.*; ParticleSystem physics; Particle[] particles; Particle mouse; int attoCount=0; void setup() { PFont fontA = loadFont("bodoni.vlw"); textFont(fontA, 14); textAlign(CENTER); size( 400, 400 ); smooth(); fill( 255 ); stroke(255); frameRate( 24 ); ellipseMode( CENTER ); physics = new ParticleSystem( 0.0, 0.15 ); particles = new Particle[10]; particles[0] = physics.makeParticle( 5.0, width/2, height/2, 0 ); //particles[0].makeFixed(); for ( int i = 1; i < particles.length; ++i ) { particles[i] = physics.makeParticle( 1.0, width/2, height/2+i, 0 ); physics.makeSpring( particles[i-1], particles[i], 4.0, .1, 1.01 ); } particles[particles.length-1].setMass( 1.0 ); mouse = physics.makeParticle( 5.0, width/2, height/2, 0); mouse.makeFixed(); physics.makeAttraction( mouse, particles[0], 10000, 10 ); // physics.makeAttraction( mouse, particles[particles.length-1], 10000, 10 ); physics.makeAttraction( particles[0],particles[particles.length-1], -10000, 5 ); } void draw() { background( 63,151,181 ); physics.advanceTime( .51 ); if(frameCount<500) text("preludio",width/2, height/2-180); if((frameCount)%500==0){ attoCount++; mouse.moveTo( random(0,500), random(0,500), 0 ); } if(frameCount>500) text(attoCount+"¡ "+"atto",width/2, height/2-180); fill( 255); ellipse( mouse.position().x(), mouse.position().y(), 8, 8 ); /* if ( mousePressed ) { particles[particles.length-1].moveTo( mouseX, mouseY, 0 ); // particles[particles.length-1].velocity().clear(); } */ beginShape( ); noFill(); curveVertex( particles[0].position().x(), particles[0].position().y() ); for ( int i = 0; i < particles.length; ++i ) { curveVertex( particles[i].position().x(), particles[i].position().y() ); } curveVertex( particles[particles.length-1].position().x(), particles[particles.length-1].position().y() ); endShape(); fill(255); ellipse( particles[0].position().x(), particles[0].position().y(), 2, 2 ); //ellipse( particles[particles.length-1].position().x(), particles[particles.length-1].position().y(), 1, 1 ); handleBoundaryCollisions( particles[0] ); handleBoundaryCollisions( particles[particles.length-1] ); } /* void mouseReleased() { particles[particles.length-1].setVelocity( (mouseX - pmouseX), (mouseY - pmouseY), 0 ); } */ void handleBoundaryCollisions( Particle p ) { if ( p.position().x() < 0 || p.position().x() > width ) p.setVelocity( -0.9*p.velocity().x(), p.velocity().y(), 0 ); if ( p.position().y() < 0 || p.position().y() > height ) p.setVelocity( p.velocity().x(), -0.9*p.velocity().y(), 0 ); p.moveTo( constrain( p.position().x(), 0, width ), constrain( p.position().y(), 0, height ), 0 ); }