processing-GUI:G4P library-GSlider2D (滑动器):setLimitsX(),setLimitsY(),getValueXI().getValueYI()

来源:互联网 发布:即时消息软件 编辑:程序博客网 时间:2024/05/16 18:09

/*the webset of learning G4Phttp://www.lagers.org.uk/g4pthe webset of learning MySQLhttp://bezier.de/processing/libs/sql/http://wiki.processing.org/w/How_to_Install_a_Contributed_Library*/import g4p_controls.*;GSlider2D sdrSniper;PImage imgScene, imgSight;// Lens propertiesint lsize = 40, lsize2 = lsize * lsize;//mag abd k are used to control the size of enlargementfloat mag = 2.0f;float k = -0.00002;int sightX, sightY;int border, borderViaLens;public void setup() {  size(540, 460);  cursor(CROSS);  imageMode(CENTER);  imgScene = loadImage("backdrop.jpg");  imgSight = loadImage("sight.png");  // border colours  borderViaLens = color(0, 80, 0);    //create a slider in a rect(180,340,180,100);  sdrSniper = new GSlider2D(this, 180, 340, 180, 100);    //the default initial value of x is 0,and y is 0  //set x initial value:180 ; limit slider's X position between 60 and 480  sdrSniper.setLimitsX(180, 60, 480);  //set y initial value:150 ; limit slider's Y position between 60 and 280  sdrSniper.setLimitsY(150, 60, 280);    //setEasing(float move) : the value of move increase but the speed of move decrease  sdrSniper.setEasing(10);    //Determines whether to show the tab and panel back colour.  sdrSniper.setOpaque(true);    //getValueXI(),getValueYI(): get the current X,Y value as an integer. DECIMAL and EXPONENT value types will be rounded to the nearest integer.  sightX = sdrSniper.getValueXI();  sightY = sdrSniper.getValueYI();  //println(sightX+" "+sightY);}public void draw() {  background(imgScene);  showLens(sightX, sightY);  image(imgSight, sightX, sightY);}void mousePressed(){  println(mouseX+" "+mouseY);}//connect small rectangle with circle to use rectangle control circle public void handleSlider2DEvents(GSlider2D slider2d, GEvent event) {  if (slider2d == sdrSniper) {    sightX = sdrSniper.getValueXI();    sightY = sdrSniper.getValueYI();  }}//the function is used to make image display biggerpublic void showLens(int x, int y) {  int u, v, r2;  float f;  for (int vd = - lsize; vd < lsize; vd++) {    for (int ud = - lsize; ud < lsize; ud++) {      r2 = ud*ud + vd*vd;      if (r2 <= lsize2) {        f = mag + k * r2;        u = floor(ud/f) + x;        v = floor(vd/f) + y;        if (u >= 0 && u < imgScene.width && v >=0 && v < imgScene.height)          set(ud + x, vd + y, imgScene.get(u, v));        else           set(ud + x, vd + y, borderViaLens);      }    }  }}


0 0
原创粉丝点击