首页 > Sktech > 习作AE_雨刮器效果
2017
10-15

习作AE_雨刮器效果

习作AE_雨刮器效果 - 第1张  | Processing编程艺术

 


简单练习ArrayList的用法。


在2.2.1内制作, 用3.0以上运行可能会报错。


//--
//--
EcWiper pbTheWiper;
ArrayList<EcPinky> pbHisPinkyList;
//--
//--

void setup() {size(500, 500);
  frameRate(30);noStroke();textAlign(LEFT,TOP);ellipseMode(CENTER);
  frame.setTitle("MsWiper");
  //--
  pbTheWiper=new EcWiper();
  //--
  pbHisPinkyList=new ArrayList<EcPinky>();
  for(int i=0;i<100;i++){
    pbHisPinkyList.add(new EcPinky());
  }
  
  //--
}//+++



void draw() { 
  background(0);
  //--
  for(EcPinky it:pbHisPinkyList){
    it.ccUpdate();
    it.ccGotDragged(pbTheWiper.cmX);
    if(pbTheWiper.cmIsAtTheVeryEnd){it.ccReset();}
  }
  pbTheWiper.ccUpdate();
  //--
}//+++


class EcWiper{
  float cmX;
  boolean cmIsAtTheVeryEnd;
  EcWiper(){
    cmX=0;
    cmIsAtTheVeryEnd=false;
  }
  //--
  void ccUpdate(){
    cmX+=1.2f;if(cmIsAtTheVeryEnd){cmX=0;}
    stroke(0xEE,0x33,0x33);line(cmX,0,cmX,height);noStroke();
    cmIsAtTheVeryEnd=(cmX>499);
  }
  //--
}

class EcPinky{
  PVector cmPos;
  float cmDia;
  EcPinky(){
    cmPos=new PVector(random(1,499),random(1,499));
    cmDia=random(1,30);
  }
  //--
  void ccUpdate(){
    fill(0xFF,0x64);
    ellipse(cmPos.x, cmPos.y, cmDia, cmDia);
  }
  //--
  void ccGotDragged(float pxLine){
    cmPos.x=pxLine>cmPos.x?pxLine:cmPos.x;
  }
  void ccReset(){
    cmPos.x=random(1,499);
    cmPos.y=random(1,499);
  }
  //--
}//+++

 



最后编辑:
作者:constrain
nullpointerexception

习作AE_雨刮器效果》有 3 条评论

  1. 卡萨布兰卡 说:
  2. 卡萨布兰卡 说:

constrain的回复 取消回复

你的email不会被公开。