class Ball { float wWidth; float wHeight; float bSize; float x, y; float xDirection, yDirection; color a; Ball(color bodya, float windowWidth, float windowHeight, float ballSize) { wWidth = windowWidth; wHeight = windowHeight; bSize = ballSize; x =1; y = 1; xDirection = 1; yDirection = 1; a=bodya; } Ball(color a, float windowWidth, float windowHeight, float ballSize,float xPosition, float yPosition,float xDir,float yDir) { this(a,windowWidth, windowHeight, ballSize); x = xPosition+random(100); y = yPosition+random(100); xDirection = xDir; yDirection = yDir; } void compute() { if (x < wWidth+100 && x > -100) { // Move along x axis x =x+ xDirection; } else { //direction xDirection = xDirection * -1; x =x+ xDirection; } if (y < wHeight+100 && y > -100) { y =y+ yDirection+random(3); } else { yDirection = yDirection * -1; y =y+ yDirection; } } void display() { compute(); fill(a); ellipseMode(CENTER); ellipse(x,y,bSize*2.5,bSize); /////////////eye & tail, change direction if (xDirection > 0 && yDirection > 0) { fill(255); ellipse(x+4,y,2,2); fill(0); ellipse(x+5,y,2,2); fill(a); triangle(x,y,x-17,y-5,x-17,y+5); } else if (xDirection > 0 && yDirection < 0) { fill(255); ellipse(x+4,y,2,2); fill(0); ellipse(x+5,y,2,2); fill(a); triangle(x,y,x-17,y-5,x-17,y+5); } else if (yDirection > 0 && xDirection < 0) { fill(255); ellipse(x-4,y,2,2); fill(0); ellipse(x-5,y,2,2); fill(a); triangle(x,y,x+17,y-5,x+17,y+5); } else if (xDirection < 0 && yDirection < 0) { fill(255); ellipse(x-5,y,4,4); fill(0); ellipse(x-5,y,2,2); fill(a); triangle(x,y,x+17,y-5,x+17,y+5); } } }