Created
February 6, 2014 22:09
-
-
Save atduskgreg/8853485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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