Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created February 6, 2014 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atduskgreg/8853485 to your computer and use it in GitHub Desktop.
Save atduskgreg/8853485 to your computer and use it in GitHub Desktop.
// world parameters
float startForce = 2.5;
float gravity = 1;
float squash = 0.2;
float r = 50; // ball radius
PVector p;
PVector g;
PVector ball;
PVector f;
void setup(){
frameRate(30);
size(1000, 500);
g = new PVector(0, gravity);
p = new PVector(0,0);
ball = new PVector(r,r);
f = new PVector(0,0);
f.add(new PVector(startForce, 0));
}
void update(){
f.add(g);
if(p.y >= (height-r/2)){
f.y = -f.y*(1 - squash);
ball.x = ball.x * (1+squash);
ball.y = ball.y * (1-squash);
} else {
ball.x = r;
ball.y = r;
}
p.add(f);
}
void draw(){
update();
background(255);
fill(0);
noStroke();
ellipse(p.x, p.y, ball.x, ball.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment