• fullscreen
  • colors.pde
  • control.pde
  • slideBar[] controls;
    PFont maTypo;
    
    void setup(){
      size(500,500); 
      // creating a type using arial
      maTypo=createFont("arial",10, false);
      textFont(maTypo,10);
      // instancing of the three slidebars
      controls=new slideBar[3];
      controls[0] = new slideBar(10,10,300,16,0,255);
      controls[1] = new slideBar(10,30,300,16,0,255);
      controls[2] = new slideBar(10,50,300,16,0,255);
    }
    
    void draw(){
      background(controls[0].val,controls[1].val,controls[2].val);
      for(int a=0;a<controls.length;a++){
        controls[a].dessine();
      }
    }
    
    void mouseReleased(){
      for(int a=0;a<controls.length;a++){
        controls[a].lache();
      }
    }
    
    
    // quick and dirty slidebar
    // instance as :
    // new slideBar(x,y,width,height,minimum value, maximum value);
    // the output will be stuck in (mySlidebar).val
    
    class slideBar{
      int x,y,h,l;
      float mi,  ma, val,pos,tot;
      boolean caught;
      slideBar(int _x, int _y, int _l, int _h, float _mi, float _ma){
        x=_x; 
        y=_y;
        h=_h;
        l=_l;
        mi=_mi;
        ma=_ma;
        val=0;
        tot= (ma-mi)/l; 
        caught=false;
        pos=0;
      }
      void dessine(){
        if(mousePressed ){
          if(mouseX>x && mouseX<x+l && mouseY>y && mouseY<y+h){
            caught=true;
          } 
          if(caught){
            pos=constrain(mouseX, x, x+l);
            val =  (pos-x)*tot  ; 
            // tell the others to drop
            for(int a=0;a<controls.length;a++){
              if (controls[a] != this){
                controls[a].caught=false;
              }
            }
          }
        }
        fill(255);
        rect(x,y,l,h);
        line(pos,y,pos,y+h);
        int vvv = int(val);
        fill(255-controls[0].val,255-controls[1].val,255-controls[2].val);
        text(vvv, x+l+10, y+10);
      } 
      void lache(){
        caught=false;
      }
    } 
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Jean-no

    Quick and dirty color selector

    Add to Faves Me Likey@! 6
    You must login/register to add this sketch to your favorites.

    The three control bars alow you to modify the background color by setting its red, green and blue channels.

    Guigui plus+
    18 Jul 2009
    hehe, remixed!
    Guigui plus+
    18 Jul 2009
    Plus propre? En tout cas j'ai laissé tomber la colorisation de l'écriture des valeurs par flemme de l'adapter aux différents fonds. Mais c'est plus classe avec.
    urzq
    21 Feb 2012
    Hello !
    Do you know there is a library named "controlp5", which provide sliders ?
    However, I do understand you prefer to implement your own :)
    You need to login/register to comment.