Traer Physic Window
in
Share your Work
•
2 years ago
Nothing special but something that i thought might be useful for some of you.
I made a little adaption to the first traer physic example sketch. http://murderandcreate.com/physics/
move the pendulum by moving the sketch window itself .
Have fun.
I made a little adaption to the first traer physic example sketch. http://murderandcreate.com/physics/
move the pendulum by moving the sketch window itself .
Have fun.
import traer.physics.*;
ParticleSystem physics;
Particle p;
Particle anchor;
Spring s;
int mX;
int mY;
int pX;
int pY;
float velX;
float velY;
void setup()
{
size( 400, 400 );
smooth();
fill( 0 );
ellipseMode( CENTER );
background(255);
physics = new ParticleSystem( 0, 0.05 );
p = physics.makeParticle( 1.0, width/2, height/2, 0 );
anchor = physics.makeParticle( 1.0, width/2, height/2, 0 );
anchor.makeFixed();
s = physics.makeSpring( p, anchor, 0.01, 0.051, 0 );
mX = 0;
pX = 0;
mY = 0;
pY = 0;
}
void draw(){
//
fill(255,30);
rect(0,0,width,height);
physics.tick();
mX = frame.getLocation().x;
mY = frame.getLocation().y;
velX = (mX-pX)/15.0;
velY = (mY-pY)/15.0;
p.velocity().add( -velX,-velY,0 );
println(velX);
fill(0,210);
noStroke();
line( p.position().x(), p.position().y(), anchor.position().x(), anchor.position().y() );
ellipse( anchor.position().x(), anchor.position().y(), 5, 5 );
ellipse( p.position().x(), p.position().y(), 10, 10 );
pX = mX;
pY = mY;
}