Wednesday, February 8, 2017

slider 1

import de.bezier.guido.*;
Slider miSlider;
void setup() {
  size(1080, 720);
  Interactive.make( this );
  miSlider= new Slider(20, 20, width-40, 32);
}
void draw(){
background (0);

String texto =str(miSlider.value);
text(texto, width/2, height/2);
fill (255);
//text("lo que hace el slider", 33,23);
}
public class Slider
{
    float x, y, width, height;
    float valueX = 0, value;
   
    Slider ( float xx, float yy, float ww, float hh )
    {
        x = xx;
        y = yy;
        width = ww;
        height = hh;
       
        valueX = x;
   
        // register it
        Interactive.add( this );
    }
   
    // called from manager
    void mouseDragged ( float mx, float my )
    {
        valueX = mx - height/2;
       
        if ( valueX < x ) valueX = x;
        if ( valueX > x+width-height ) valueX = x+width-height;
       
        value = map( valueX, x, x+width-height, 0, 1 );
    }

    void draw ()
    {
        noStroke();
       
        fill( 100 );
        rect(x, y, width, height);
       
        fill( 120 );
        rect( valueX, y, height, height );
    }
}

No comments:

Post a Comment