2018年10月18日 星期四

QAQ筆記 WEEK06

目標:做出水果忍者

1.先劃出一個會做拋物線的圓形


2.再畫出很多個












程式碼如下:
float []fX=new float[20];
float []fY=new float[20];
float []fVX=new float[20];
float []fVY=new float[20];
void setup(){
  size(800,600);
  for(int i=0;i<20;i++){
    fX[i]=random(800);  fVX[i]=3;
    fY[i]=700;  fVY[i]=-35;
  }
}
void draw(){
  background(0);
  for(int i=0;i<20;i++){
    ellipse(fX[i],fY[i],100,100);
    fX[i]+=fVX[i];
    fY[i]+=fVY[i];
    fVY[i]+=0.98;
  }
}


3.亂飛的球


程式碼如下:
float []fX=new float[20];
float []fY=new float[20];
float []fVX=new float[20];
float []fVY=new float[20];
void reborn(int i){
  fX[i]=random(800);  fVX[i]=(6)-3;
  fY[i]=700;  fVY[i]=-35;
}
void setup(){
  size(800,600);
  for(int i=0;i<20;i++){
    reborn(i);
  }
}
void draw(){
  background(0);
  for(int i=0;i<20;i++){
    if(dist(mouseX,mouseY,fX[i],fY[i])<=50){
      reborn(i);  continue;
    }
    ellipse(fX[i],fY[i],100,100);
    fX[i]+=fVX[i];
    fY[i]+=fVY[i];
    fVY[i]+=0.98;
    if(fY[i]>700)  reborn(i);
  }
}

沒有留言:

張貼留言