2019年9月19日 星期四

Week02_

1.draw

void setup(){
  size(800,300);
}
void draw(){
  rect(mouseX,mouseY, 50,20); //滑鼠在哪,畫到哪
}
void setup(){
  size(800,300);
}
void draw(){
  int nowX=mouseX/16*16, nowY=mouseY/30*30; //無條件捨去,始洞等距
  if(mousePressed){ //當滑鼠按下
   fill(0);
   rect(nowX,nowY, 12,25);
  }
}

2.PImage

PImage img; //圖片宣告
void setup(){
  size(800,300);
  img=loadImage("https://www.pegipegi.com/travel/wp-content/uploads/2015/04/Pantai-Sanur.png");
  image(img, 0,0, 800,300); //貼圖片
}
void draw(){
  int nowX=mouseX/16*16, nowY=mouseY/30*30;
  if(mousePressed && mouseButton==LEFT){ //左鍵挖空
   noStroke();
   fill(0);
   rect(nowX,nowY, 12,25);
  }
  else if(mousePressed && mouseButton==RIGHT){ //右鍵填白
   noStroke();
   fill(255);
   rect(nowX,nowY, 12,25);
  }
}

3.

PImage img;
int [][] table= new int[45][14];
void setup(){
  size(582,388); //大小要和圖片一樣
  img=loadImage("Sanur.png"); //要將圖檔加入資料夾中
}
void draw(){
  background(img); //要將圖片當背景
  int nowi=mouseX/16, nowj=mouseY/30;
  if(mousePressed && mouseButton==LEFT){
    table[nowi][nowj]=1; //要打洞
  }else if(mousePressed && mouseButton==RIGHT){
    table[nowi][nowj]=0; //不打洞
  }
  for(int i=0;i<45;i++){
    for(int j=0;j<14;j++){
      fill(0);
      if(table[i][j]==1) rect(i*16,j*30, 12,25);
    }
  }
}


沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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