> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://hewitt.sketchpad.cc/sp/pad/view/ro.himI$L$OxT6/rev.8
 * 
 * authors: 
 *   Erik Nauman

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



Circle circle;
Button[] button = new Button[3];
boolean r_on,g_on,b_on;

void setup() {
  size(500,500);
  smooth();
  noStroke();
  circle = new Circle();
  for(int i = 0; i < button.length; i++) {
    button[i] = new Button();
  }//end for
}//end setup

void draw() {
  background(100);
  if(r_on && !g_on && !b_on) {
    circle.setColor(255,0,0);
    for(int i = 0;i < button.length; i++) {
      button[i].redOn();
    }//endfor
  } else if(!r_on && g_on && !b_on) {
    circle.setColor(0,255,0);
    for(int i = 0;i < button.length; i++) {
      button[i].greenOn();
    }//endfor
  } else if(!r_on && !g_on && b_on) {
    circle.setColor(0,0,255);
    for(int i=0; i < button.length; i++) {
      button[i].blueOn();
   }//endfor
  } else if(r_on && g_on && !b_on) {
    circle.setColor(255,255,0);
    for(int i=0; i < button.length; i++) {
      button[i].yellowOn();
    }//endfor
  } else if(r_on && !g_on && b_on) {
    circle.setColor(255,0,255);
    for(int i=0; i < button.length; i++) {
      button[i].magentaOn();
    }//endfor
  } else if(!r_on && g_on && b_on) {
    circle.setColor(0,255,255);
    for(int i=0; i < button.length; i++) {
      button[i].cyanOn();
    }//endfor
  } else if(r_on && g_on && b_on){
    circle.setColor(255,255,255);
    for(int i=0; i < button.length; i++) {
      button[i].whiteOn();
    }//endfor
  } else {
    circle.setColor(0,0,0);
    for(int i = 0; i < button.length; i++) {
      button[i].blackOn();
    }//endfor
  }//endelse
  circle.display();
}//end draw

void mousePressed() {
  if(dist(mouseX,mouseY,width/4,height/5*4) < 25) {
    r_on = !r_on;
  }
  if(dist(mouseX,mouseY,width/2,height/5*4) < 25) {
    g_on = !g_on;
  }
  if(dist(mouseX,mouseY,width/4*3,height/5*4) < 25) {
    b_on = !b_on;
  }
}//end void

class Button {
  //arrays for r,g,b values for 3 buttons
  int[] r = new int[3];
  int[] g = new int[3];
  int[] b = new int[3];
  int[] xpos = new int[3];

  Button() {
  xpos[0] = width/4;
  xpos[1] = width/2;
  xpos[2] = width/4*3;
}
  
  void display(int br, int bg, int bb, int x) {
    fill(br,bg,bb);
    ellipse(x,height/5*4,50,50);
  }
  
  void redOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
      g[i] = 0;
      b[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }
  }
  
  void greenOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
      r[i] = 0;
      b[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void blueOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      r[i] = 0;
      g[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void yellowOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
       if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
      b[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void magentaOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
       if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      g[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void cyanOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
       if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      r[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void whiteOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
       if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
       if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void blackOn() {
    for(int i=0; i < button.length; i++) {
      button[i].display(0,0,0,xpos[i]);
    }//endfor
  }//endvoid
}//end class

class Circle {
  int rC = 0;
  int gC = 0;
  int bC = 0;
  PFont f;
  
  Circle() {
    f = createFont("Arial", 30,true);
    textFont(f);
  }//end const
  
  void setColor(int red,int green, int blue) {
    rC = red;
    gC = green;
    bC = blue;
  }//end void
  
  void display() {
    fill(rC,gC,bC);
    ellipse(width/2,height/2-50,250,250);
    textAlign(CENTER);
    text("(" + rC + "," + gC + "," + bC + ")", width/2,40);
  }//end void  
}//end class