Skip to content

Instantly share code, notes, and snippets.

@clavis-magna
Created November 23, 2013 00:01
Show Gist options
  • Save clavis-magna/7608948 to your computer and use it in GitHub Desktop.
Save clavis-magna/7608948 to your computer and use it in GitHub Desktop.
bouncing ball
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