Created
November 23, 2013 00:01
-
-
Save clavis-magna/7608948 to your computer and use it in GitHub Desktop.
bouncing ball
This file contains hidden or 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
float x = 100; | |
float y = 100; | |
float xSpeed = 1; | |
float ySpeed = 3.3; | |
void setup(){ | |
size(200,200); | |
smooth(); | |
background(255); | |
} | |
void draw(){ | |
background(0); | |
changeSpeed(); | |
testEdge(); | |
drawBall(50,50); | |
} | |
void changeSpeed(){ | |
x=x+xSpeed; | |
y=y+ySpeed; | |
} | |
void testEdge(){ | |
if(x > width || x < 0){ | |
xSpeed = xSpeed * -1; | |
} | |
if(y > height || y < 0){ | |
ySpeed = ySpeed * -1; | |
} | |
} | |
void drawBall(int xwidth, int yheight){ | |
stroke(0); | |
fill(175); | |
ellipse(x,y,xwidth,yheight); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment