heerdyes_processing-sketching/physics/zU/physics/physics.pde
MoverSystem msys;
PVector gravity;
int worldrefreshduration=3;

void setup(){
  size(600,400);
  background(0);
  msys=new MoverSystem(10);
  gravity=new PVector(0,0.2);
}

void transwipe(){
  fill(0,0,0,32);
  rect(0,0,width,height);
}

void togglegravity(){
  if(gravity.mag()<0.00001){
    gravity.y=0.3;
    gravity.x=0.0;
  }else{
    gravity.mult(0);
  }
}

void renderctrlpanel(){
  fill(0);
  rect(5,5,120,50);
  fill(0,255,128);
  textSize(11);
  textAlign(LEFT,TOP);
  text("g=["+nf(gravity.x,2,2)+" "+nf(gravity.y,2,2)+"]",7,7);
  //text("v=["+nf(mover.velocity.x,2,2)+" "+nf(mover.velocity.y,2,2)+"]",7,17);
}

void draw(){
  transwipe();
  renderctrlpanel();
  msys.enliven();
}

void keyPressed(){
  println(keyCode);
  // right arrow -> 37
  if(keyCode==37){
    msys.applyforce(new PVector(-0.05,0));
  }
  if(keyCode==39){
    msys.applyforce(new PVector(0.05,0));
  }
  if(keyCode==38){
    msys.applyforce(new PVector(0,-0.05));
  }
  if(keyCode==40){
    msys.applyforce(new PVector(0,0.05));
  }
  // g -> 71
  if(keyCode==71){
    togglegravity();
  }
}
