2019年10月24日 星期四

喬的耍費日常

使用新的物件讓含數計算

PVector user; //宣告新的物件
PVector userV; //加速度的變數
void setup(){
  size(400,400);
  user = new PVector(200,200); //初始的座標
  userV = new PVector(1,1); //加速度
}
void draw(){
  background(255);
  ellipse(user.x,user.y,100,100); //畫圖
  user.add(userV); //圓心加上加速度
  if(user.x>400-50) userV.x=-1;
  if(user.y>400-50) userV.y=-1;
  if(user.x<50) userV.x=+1;
  if(user.y<50) userV.y=+1;
}









































電流急急棒

PImage imgMap;
PVector user;
PVector userV;
void setup(){
  size(400,400);
  imgMap=loadImage("map.png");
  imgMap.loadPixels();
}
void draw(){
  background(imgMap);
  if(imgMap.pixels[mouseX+mouseY*400]==color(237,28,36)){
    //mouseX+mouseY*400
    
    background(255,0,0);
  }
  fill(imgMap.pixels[mouseX+mouseY*400]);
  rect(250,250,100,100);
}




































動態星星宇宙

int[] value = new int[100]; //準備[陣列]的格子100個
PVector[] bullet = new PVector[100];//準備[陣列]的格子100個
PVector[] bulletV = new PVector[100];//準備[陣列]的格子100個
void setup(){
  size(500,500);
  for(int i=0; i<100; i++){
    bullet[i] = new PVector(random(500),random(500)); //(圓括號)
    bulletV[i] = new PVector(random(4)-2,random(4)-2);//(圓括號)
  }
}
void draw(){
  background(0);
  for(int i=0; i<100; i++){
    fill(255);
    bullet[i].add(bulletV[i]);
    ellipse(bullet[i].x, bullet[i].y,5,5);
    if(bullet[i].x<0){bullet[i].x=0; bulletV[i].x= random(2);}
    if(bullet[i].x>500){bullet[i].x=500; bulletV[i].x= -random(2);}
    if(bullet[i].y<0){bullet[i].y=0; bulletV[i].y= random(2);}
    if(bullet[i].y>500){bullet[i].y=500; bulletV[i].y= -random(2);}
  }
}


沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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