Skip to content

Instantly share code, notes, and snippets.

@Introscopia
Created April 28, 2017 22:03
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 Introscopia/c971082046b25bfa2123ff10bb190722 to your computer and use it in GitHub Desktop.
Save Introscopia/c971082046b25bfa2123ff10bb190722 to your computer and use it in GitHub Desktop.
bouncing ball demo LVL.2
PVector pos, vel;
float R, D;
void setup(){
size(400, 400);
pos = new PVector( 200, 200 );
vel = new PVector( random(-3, 3), random(-3, 3) );
R = 10;
D = 2 * R;
}
void draw(){
background(202);
if( pos.x - R <= 0 ) vel.x *= -1;
if( pos.y - R <= 0 ) vel.y *= -1;
if( pos.x + R >= 400 ) vel.x *= -1;
if( pos.y + R >= 400 ) vel.y *= -1;
//pos.x += vel.x;
//pos.y += vel.y;
pos.add( vel );
ellipse( pos.x, pos.y, D, D );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment