//Dennis Malcolm class Ball { float d; // diameter float x; // x position float y; // y position float sx; // speed in x direction float sy; // speed in y direction float dx; // x direction, must be 1 or -1 float dy; // y direction, must be 1 or -1 Ball() { // populate the arrays with initial values d = 50; x = random(width); y = random(height); sx = random(20); sy = random(20); dx = (boolean(round(random(1)))) ? 1 : -1; dy = (boolean(round(random(1)))) ? 1 : -1; } void display() { // draw the ball smooth(); fill(255); ellipse(x, y, d, d); } void move() { // increment x and y by speeds and apply direction x += sx * dx; y += sy * dy; // test for x values less than zero and greater than width // if true, then reverse direction of x if (x <= 0) { dx = 1; } else if (x >= width) { dx = -1; } // test for y values less than zero and greater than height // if true, then reverse direction of y if (y <= 0) { dy = 1; } else if (y >= height) { dy = -1; } } }