// The name of our class class Ball { // our Class variables. int wWidth; int wHeight; int bSize; int x, y; int xDirection, yDirection; // Constructor. This gets called when we create a "new Ball" Ball(int windowWidth, int windowHeight, int ballSize) { wWidth = windowWidth; wHeight = windowHeight; bSize = ballSize; x = 1; y = 1; xDirection = 1; yDirection = 1; } Ball(int windowWidth, int windowHeight, int ballSize, int xPosition, int yPosition) { this(windowWidth, windowHeight, ballSize); x = xPosition; y = yPosition; } // Our method to determine current position of the ball. void compute() { if (x < wWidth && x > 0) { // Move along x axis x += xDirection; } else { // Change direction, from positive to negative and vice versa xDirection = xDirection * -1; x += xDirection; } if (y < wHeight && y > 0) { y += yDirection; } else { yDirection = yDirection * -1; y += yDirection; } } // This actually displays our ball, it gets called in the main draw function void display() { compute(); // first we run the computation ellipseMode(CENTER); ellipse(x,y,bSize,bSize); } }