jazz
Ex Member
Re: getting the direction of a moving point
Reply #4 - Feb 1st , 2009, 11:57am
Thats cool, i never thought about this solution. But the line was just an example for some more complex brushes. Do you have any other tipps if it would look like this ? import traer.physics.*; Particle mouse, b; ParticleSystem physics; void setup() { size( 400, 400 ); frameRate( 24 ); smooth(); ellipseMode( CENTER ); noStroke(); noCursor(); physics = new ParticleSystem( 0, 0.1 ); mouse = physics.makeParticle(); mouse.makeFixed(); b = physics.makeParticle( 1.0, random( 0, width ), random( 0, height ), 0 ); physics.makeAttraction( mouse, b, 10000, 10 ); } void draw() { mouse.moveTo( mouseX, mouseY, 0 ); handleBoundaryCollisions( b ); physics.tick(); // background( 255 ); fill( 255, 0, 0 ); ellipse( mouse.position().x(), mouse.position().y(), 5, 5 ); stroke(0); strokeWeight(1); line(b.position().x()-10, b.position().y(),b.position().x()+10, b.position().y()); fill(244,0,0); ellipse(b.position().x()-10, b.position().y(),3,3); ellipse(b.position().x()+10, b.position().y(),3,3); noStroke(); } // really basic collision strategy: 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 ); }