// A quick example to show use of if-statements // to keep a moving ball (also how to use delta variables) // withing sketch bounds... // The x, y, deltaX, deltaY for controlling the ball // location and movement int x; int y; int deltaX = 1; int deltaY = 1; // ball size int ballSize = 25; void setup() { size(400, 400); smooth(); x = int(random(width)); y = int(random(height)); } // setup() void draw() { background(255); drawBall(x, y, ballSize); x = x + deltaX; y = y + deltaY; // did I reach the right or left edge of the sketch? if ((x > width) || (x < 0)) { // move backwards deltaX = -deltaX; } // top edge? or bottom edge? if ((y < 0) || (y > height)) { deltaY = -deltaY; } } // draw() void drawBall(int x, int y, int w) { noStroke(); fill(#FA72DA); ellipse(x, y, w, w); } // drawBall()