// AUTHOR: Fawad Khan
// TITLE: Project 8
// DATE: 12/3/14



Ball redKhan;
Ball greenKhan;
Ball blueKhan;
Button colorButtons;
 
Screen screenKhan;
 
 
/*
int numButtons = 5;
 Button[] b = new Button[numButtons];
 */
 
void setup() {
  size(500, 500);
 
  redKhan= new Ball(color(255, 0, 0), 75, 100, 1);
  greenKhan= new Ball(color(0, 255, 0), 75, 200, 2);
  blueKhan= new Ball(color(255, 0, 255), 75, 300, 3);
  screenKhan= new Screen(color(0, 65, 75));
  colorButtons = new Button();
 
  /* for(int j=0; j<5; j++ {
   b[0] = new Button("MORE", 20,100);
   b[1] = new Button("FEWER",20,150);
   b[2] = new Button("FASTER",20,200);
   b[3] = new Button("SLOWER",20,250);
   b[4] = new Button("QUIT",20,300);
   b[4].kind = 1;
   */
}
 
void draw() {
  background(255);
  show();
  /*  
   for (int j=0; j<numButtons; j++) {
   b[j].show();
   }
   */
}
 
 
 
void show() {
 
  screenKhan.display();
 
  redKhan.display();
  redKhan.move();
  greenKhan.display();
  greenKhan.move();
  blueKhan.display();
  blueKhan.move();
 
  colorButtons.display();
}
 
void mousePressed() {
  colorButtons.mousePressed();
}
 
// ===========================================
 
class Ball {
  color ballA;
  float ballX;
  float ballY;
  float ballDX;
  float ballDY;
  float speed;
  float x, y;
 
  Ball(color tempBallA, float tempBallX, float tempBallY, float tempXspeed) {
    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 Screen {
  color screenA;
  float screenX;
  float screenY;
  float screenW;
  float screenH;
 
  //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);
  }
}
 
class Button {
  color buttonA;
  float buttonX;
  float buttonY;
  float buttonW;
  float buttonH;
  boolean buttonRed = false;
  boolean buttonGreen = false;
  boolean buttonBlue = false;
  boolean buttonExit = false;
  
 
  // Constructor
  Button() {
    buttonX = 5;
    buttonY = 5;
    buttonW = 50;
    buttonH = 50;
  }
  void display() {
 
    if (buttonRed) {
      redKhan.randomize();    
    }
   
    //noStroke();
    stroke(255, 2, 2); 
    fill(255);
    rect(buttonX, buttonY+20, buttonW+5, buttonY+35);
    fill(0);
    text("Red", buttonW/2.5, buttonH);
    buttonRed = false;
    
    if (buttonGreen) {
      greenKhan.randomize();
    }
     stroke(255, 2, 2); 
    fill(255);
    rect(buttonX, buttonY+80, buttonW+5, buttonY+35);
    fill(0);
    text("Green", buttonW-33, buttonH*2.2);
    buttonGreen = false;
    
    if (buttonBlue) {
      blueKhan.randomize();
    }
    stroke(255, 2, 2); 
    fill(255);
    rect(buttonX, buttonY+140, buttonW+5, buttonY+35);
    fill(0);
    text("Blue", buttonW-30, buttonH*3.4);
    buttonBlue = false;
    
    if (buttonExit) {
    }
    stroke(255, 2, 2); 
    fill(255);
    rect(buttonX, buttonY+200, buttonW+5, buttonY+35);
    fill(0);
    text("Exit", buttonW-30, buttonH*4.6);
    buttonExit = false;
    
  }
  void mousePressed() {
    if (mouseX > buttonX && mouseX < buttonX+buttonW && 
      mouseY > buttonY+20 && mouseY < buttonY+buttonH) {
      buttonRed = !buttonRed;
      }
      if (mouseX > buttonX && mouseX < buttonX+buttonW && 
      mouseY > buttonY+80 && mouseY < buttonY+buttonH) {
      buttonGreen = !buttonGreen;
      }
      if (mouseX > buttonX && mouseX < buttonX+buttonW && 
      mouseY > buttonY+140 && mouseY < buttonY+buttonH) {
      buttonBlue = !buttonBlue;
      }
      if (mouseX > buttonX && mouseX < buttonX+buttonW && 
      mouseY > buttonY+200 && mouseY < buttonY+buttonH) {
      exit();
      }
  }
}
      
     
 
 
/*
void mousePressed() {
 if (b[4].click(mouseX,mouseY)) {exit(); } or 
 if (b[4].click(mouseX,mouseY)) {b[4].size = 1.5;}
 
 
 class Button {
 int kind = 2;
 float x,y;
 float w=30, h=10;
 String s="";
 int r,g,b;
 float size = 1;
 
 // CONSTRUCTORS
 Button(String s, float x ,float y, int r, int b , int g) {
 this.s =s;
 this.x =x;
 this.y = y;
 this.r =r;
 this.g = g;
 this.b = b;
 }
 //method
 void show() {
 fill(r,g,b);
 if (kind == 1) {
 ellipseMode(CENTER);
 ellipse(x,y,w,h);
 } else if (kind == 2 || kind == 4) {
 rectMode(CENTER);
 rect(x,y,w,h);
 } else if (kind == 3) {
 triangle(x-w/2,y+h/w,x+w/2,y+h/2,x,y-h/2);
 } else{
 text( "NO SUCH BUTTON EXIST" +kind, x,y);
 }
 fill(0);
 text(s,x-w/2+20,y);
 }  
 boolean click( float xx, float yy ) {
 if (kind == 1) return(dist(mouseX, mouseY, 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;
 }
 */
