2019年10月31日 星期四

討厭的下雨天

今天教的是如何使用函式

PVector[] cup=new PVector[3];
PVector[] cupV=new PVector[3];
int guess;
void setup(){
  size(400,300);
  for(int i=0;i<3;i++){
     cup[i]=new PVector(100+i*100,100);
     cupV[i]=new PVector(random(4),random(3));
  }
     guess= int(random(3));
     println(guess);
}
void draw(){
  background(255);
  for(int i=0;i<3;i++){
    cup[i].add(cupV[i]);
    if(cup[i].x<0 || cup[i].x>400) cupV[i].x *= -1;
    if(cup[i].y<0 || cup[i].y>300) cupV[i].y *= -1;
    fill(255);
    ellipse(cup[i].x, cup[i].y,90,60);
  }
}





Cup[] cup=new Cup[3];
int guess;
void setup(){
  size(400,300);
  for(int i=0;i<3;i++){
     cup[i]=new Cup(100+i*100,100);
  }
     guess= int(random(3));
    cup[guess].coin=true;
}
class Cup{
  PVector pos;
  PVector v;
  boolean coin=false;
  Cup(float x,float y){
    pos = new PVector(x,y);
    v =new PVector(random(4),random(3));
  }
  void draw(){
    pos.add(v);
    if(pos.x<0 || pos.x>400) v.x *= -1;
    if(pos.y<0 || pos.y>400) v.y *= -1;
    fill(255);
    ellipse(pos.x,pos.y,90,60);
  }
}
void draw(){
  background(255);
  for(int i=0;i<3;i++){
    cup[i].draw();
    if(mousePressed && cup[i].coin==true){ 
    fill(255,255,0);
    ellipse(cup[i].pos.x, cup[i].pos.y,90,60);
    }
  }
}





沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

回顧這學期的作品:  期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...