// AUTHOR: Fawad Khan // TITLE: Project 9 // DATE: 12/10/14 Ball[] khan = new Ball[5]; Button[] fawad = new Button[5]; Screen colorScreen; void setup() { size(500, 500); smooth(); khan[0] = new Ball(color(255, 20, 102)); khan[1] = new Ball(color(200, 16, 100)); khan[2] = new Ball(color(200, 100, 10)); khan[3] = new Ball(color(200, 200, 200)); khan[4] = new Ball(color(200, 255, 255)); colorScreen = new Screen(color(184, 2, 2)); fawad[0] = new Button(color(255,0,0), 200, 200, 15, 15, "RED"); fawad[1] = new Button(color(255, 44, 255), 200, 200, 15, 15, "GREEN"); fawad[2] = new Button(color(255, 12, 12), 300, 300, 15, 15, "BLUE"); fawad[3] = new Button(color(12, 12, 255), 400, 400, 15, 15, "EXIT"); fawad[4] = new Button(color(12, 255, 12), 500, 500, 15, 15, "TABLE"); fawad[0].kind = 1; fawad[1].kind = 2; fawad[2].kind = 3; fawad[3].kind = 4; fawad[4].kind = 1; } class Ball { color ballA; float ballX; float ballY; float ballDX; float ballDY; float speed; float x, y; Ball(color tempBallA) { ballA = tempBallA; ballX = tempBallX; ballY = tempBallY; ballDX = tempXspeed; ballDY = tempXspeed; } void display() { // show balls noStroke(); fill(ballA); ellipse(ballX, ballY, 25, 25); } void move() { // balls movement ballX = ballX + ballDX; ballY = ballY + ballDY; if ((ballX > width-50) || (ballX < 62)) { ballDX= -ballDX; } if ((ballY > height-50) || (ballY < 62)) { ballDY= -ballDY; } } void randomize() { // balls position ballX = 110 + random(110); ballY = 110 + random(110); ballDX = 1 + random(11); ballDY = 1 + random(11); } } class Button { int buttoncolor; float X, Y, W, H; boolean isHovering = false; String buttontext=""; int kind = 0; Button( int tempbuttonColor) { buttoncolor = tempbuttonColor; } void display() { if (kind == 1 || kind == 2) { rectMode( CORNER ); fill(buttoncolor); rect(X, Y, W, H); fill(0); textSize(10); text(buttontext, X, Y); } else if (kind == 2 || kind == 4) { fill(buttoncolor); rectMode(CORNER); rect(X, Y, W, H); fill(0); textSize(10); text(buttontext, X, Y); } else if ( kind == 3 || kind == 1) { fill(buttoncolor); rect(X, Y, W, H); fill(0); textSize(10); text(buttontext, X, Y); } else { text( "NO SUCH KIND" + kind, X, Y); } } boolean isHovering(float xx, float yy) { if (kind == 1 ) return dist(xx, yy, X, Y) < W; if (xx < X-W) return false; if (xx > X+W) return false; if (yy < Y-H) return false; if (yy > Y+H) return false; return true; } } class Screen { color ScreenA; float screenX; float screenY; float screenW; float screenH; boolean hit; //constructor Screen(color tempScreenA) { ScreenA= tempScreenA; screenX= 30; screenY= 30; screenW= 415; screenH= 415; } void display() { //build table fill(ScreenA); rect(screenX, screenY, screenW, screenH); } void stageCheck() { if (hit) { hit = false; ScreenA = color(188, 188, 188); return; } hit = true; ScreenA = color(184, 241, 250); return; } } void draw() { background(255); stage(); for (int j = 0; j