Created
April 28, 2017 22:03
-
-
Save Introscopia/c971082046b25bfa2123ff10bb190722 to your computer and use it in GitHub Desktop.
bouncing ball demo LVL.2
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
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