> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://hewitt.sketchpad.cc/sp/pad/view/ro.BmF9pkFqI9h/rev.72
 * 
 * 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;
Slider[] slider = new Slider[3];
int[] xpos = new int[3];
int[] ypos = new int[3];

void setup() {
  size(500,530);
  smooth();
  for (int i = 0; i < xpos.length; i++) {
    xpos[i] = (i+1)*30;
  }
  noStroke();
  circle = new Circle();
  for(int i = 0; i < slider.length; i++) {
    slider[i] = new Slider();
    ypos[i] = height-10;
  }//end for
}//end setup

void draw() {
  background(100);
  circle.setColorVars();
  circle.display();
  for(int i = 0; i < slider.length; i++) {
    int[] r = {255,0,0};
    int[] g = {0,255,0};
    int[] b = {0,0,255};
    slider[i].displayRect(r[i],g[i],b[i],xpos[i]);
    slider[i].displayHandle(xpos[i],ypos[i]);
  }//end for
}//end draw

void mouseDragged() {
  for(int i = 0;i < slider.length; i++) {
    slider[i].dragging();
  }
}

class Circle {
  int r = 0;
  int g = 0;
  int b = 0;
  PFont f;
  
  Circle() {
    f = createFont("Arial", 30,true);
    textFont(f);
  }//end const
  
  void setColorVars() {
      //cast floats to ints b/c js issue
    r = int(255 - ypos[0]/2+5);
    g = int(255 - ypos[1]/2+5);
    b = int(255 - ypos[2]/2+5);
  }

  void display() {
    fill(r,g,b);
    ellipse(width/2+50,height/2,250,250);
    textAlign(CENTER);
    text("(" + r + "," + g + "," + b + ")", width/2+50,40);
  }//end void
}//end class

class Slider {
  int btm = height-10;
  int tp = 10;

  Slider() {
  }
  
  void displayRect(int r, int g, int b, int x) {
    fill(r,g,b);
    rectMode(CENTER);
    rect(x,height/2,20,510);
  }
  
  void displayHandle(int x, int y) {
    fill(0);
    rectMode(CENTER);
    rect(x,y,20,20);
  }
  
  void dragging() {
    if(mouseY >= tp && mouseY <= btm) {
      if(dist(mouseX,mouseY,xpos[0],ypos[0]) < 20) {
        ypos[0] = mouseY;
      }//endif
      if(dist(mouseX,mouseY,xpos[1],ypos[1]) < 20) {
        ypos[1] = mouseY;
      }//endif
      if(dist(mouseX,mouseY,xpos[2],ypos[2]) < 20) {
        ypos[2] = mouseY;
      }//endif
    }//endif
  }//end void
} //end class