// Sketch: Caroming Ball
// Prupose: Shows how to move a ball and detect wall bounces (using if- statements)
// Also shows how to use if-statements
void setup() {
size(500, 500);
background(255);
} // setup()
float x = 10, y = 250, w = 20;
float speedX = 1;
float speedY = 1;
void draw() {
background(255);
fill(255, 89, 23);
noStroke();
circle(x, y, w);
x = x + speedX;
if ((x+w/2 > width) || (x - w/2 < 0)) {
speedX = -speedX;
}
y = y + speedY;
if ((y+w/2 > height) || (y - w/2 < 0)) {
speedY = -speedY;
}
} // draw()