首页 > Sktech > 习作BB_缩放切换效果
2017
09-29

习作BB_缩放切换效果

习作BB_缩放切换效果 - 第1张  | Processing编程艺术


练习向量的用法.
仿某X窗口切换效果.


– [A/D]:切换方块
– [Q]:退出


– 问题:2.0没办法使用enum…?不知道是附带的JAVA的问题还是PDE的问题.



//--
int pbLeCubeFocus=0;
//--
EcDocker pbTheDocker;
EcCube[] pbThoseCube;
//--
static final int C_ANM_SPD=6;
static final int C_ICON_SCALE=22;
static final int C_WINDOW_WIDTH=320/2;
static final int C_WINDOW_HEIGHT=240/2;
static final int C_WINDOW_X=320/4;
static final int C_WINDOW_Y=240/6;
static final int C_GRID=28;
static final int C_YOFF=240-30;
//--

void setup(){
  size(320,240);textAlign(LEFT,TOP);noStroke();
  //--
  int lpDockerHeight=20;
  pbTheDocker=new EcDocker(0,height-lpDockerHeight,width,lpDockerHeight);
  //--
  int lpCubeAmount=8;
  pbThoseCube=new EcCube[lpCubeAmount];
  for(int i=0;i<lpCubeAmount;i++){
    pbThoseCube[i]=new EcCube(i);
  }fsCheckAllCube();
  //-- 
}//+++

void draw(){
  background(0);
  //--
  fill(0x77,0xEE,0x77);
  text("[A/D]to change focused window..\n[Q]to quit..",5,5);
  //--
  pbTheDocker.ccUpdate();
  for(EcCube it:pbThoseCube){it.ccUpdate();}
  //--
}//+++

void keyPressed(){switch(key){
  //--
  case 'a':fsShiftCubeFocus(-1);break;
  case 'd':fsShiftCubeFocus( 1);break;
  //--
  case 'q':exit();break;
  default:break;
}}//+++

//-- --- --- ---
//-- --- --- ---

color fnReverseColor(color pxColor){
  return color(255-red(pxColor),255-green(pxColor), 255-blue(pxColor));
}//+++

//-- --- --- ---
//-- --- --- ---

void fsShiftCubeFocus(int pxOffset){
  pbLeCubeFocus+=pxOffset;pbLeCubeFocus&=0x07;
  fsCheckAllCube();
}//+++

void fsCheckAllCube(){
  for(EcCube it:pbThoseCube){it.ccCheckFocus(pbLeCubeFocus);}
}//+++

//-- --- --- ---
//-- --- --- ---

class EcDocker{
  int cmX, cmY, cmW, cmH;
  color cmOffColor;
  EcDocker(int pxX, int pxY, int pxW, int pxH){
    cmX=pxX;
    cmY=pxY;
    cmW=pxW;
    cmH=pxH;
    cmOffColor=color(0x77,0x77,0x77);
  }
  //--
  void ccUpdate(){
    fill(cmOffColor);
    quad(
      cmX+cmH,cmY,
      cmX+cmW-cmH,cmY,
      cmX+cmW,cmY+cmH,
      cmX,cmY+cmH
    );
  }
  //--
}//+++

class EcCube{
  //--
  boolean cmFocused;
  int cmID;
  //--
  PVector cmPos,cmDia;
  PVector cmPosTarget, cmDiaTarget;
  //--
  color cmOffColor;
  //--
  EcCube(int pxID){
    cmFocused=false;
    cmID=pxID;
    cmPos=new PVector((cmID+2)*C_GRID,C_YOFF);
    cmDia=new PVector(C_ICON_SCALE,C_ICON_SCALE);
    cmPosTarget=cmPos.get();
    cmDiaTarget=cmDia.get();
    cmOffColor=color(0xEE,0xEE,0xEE);
  }
  //--
  void ccUpdate(){
    ccCheckTarget();
    fill(cmOffColor);rect(cmPos.x,cmPos.y,cmDia.x,cmDia.y);
    fill(fnReverseColor(cmOffColor));
    text(nf(cmID,2),
      cmPos.x+cmDia.x*(cmFocused?0.5:0),
      cmPos.y+cmDia.y*(cmFocused?0.5:0)
    );
    //--
  }
  //--
  void ccCheckTarget(){
    PVector lpPosDif=PVector.sub(cmPosTarget,cmPos);
    PVector lpDiaDif=PVector.sub(cmDiaTarget,cmDia);
    lpPosDif.div(C_ANM_SPD);cmPos.add(lpPosDif);
    lpDiaDif.div(C_ANM_SPD);cmDia.add(lpDiaDif);
  }
  //--
  void ccCheckFocus(int pxID){
    cmFocused=(pxID==cmID);
    if(cmFocused){
      cmPosTarget.set(C_WINDOW_X,C_WINDOW_Y);
      cmDiaTarget.set(C_WINDOW_WIDTH,C_WINDOW_HEIGHT);
    }else{
      cmPosTarget.set((cmID+2)*C_GRID,C_YOFF);
      cmDiaTarget.set(C_ICON_SCALE,C_ICON_SCALE);
    }
  }
  //--
}//+++

 



最后编辑:
作者:constrain
constrain
nullpointerexception

留下一个回复

你的email不会被公开。