2019年9月19日 星期四

week02




畫出殘影
void setup(){ //start()
  size(800,300);
}
void draw(){ //update()
  rect(mouseX,mouseY,50,20);
}




打卡機
void setup(){ //start()

  size(800,300); //800->720 for 45
  for(int x=0;x<800;x+=16){
     for(int y=0;y<300;y+=30){
       rect(x,y,16,30);
    }
  }
} //720/45=>16
void draw(){ //update()
  int nowX=mouseX/16*16,                                                                                                                        nowY=mouseY/30*30;
                                                                                      fill(0);
                                                                                      rect(nowX,nowY,16,30);
                                                                                    }


打卡機
按滑鼠左鍵格子變黑,按滑鼠右鍵格子變白
void setup(){ //start()
  size(800,300); //800->720 for 45
  for(int x=0;x<800;x+=16){
     for(int y=0;y<300;y+=30){
       rect(x,y,16,30);
    }
  }
} //720/45=>16
void draw(){ //update()
                                                                                    int nowX=mouseX/16*16,                                                                                                                        nowY=mouseY/30*30;
                                                                                    if(mousePressed && mouseButton==LEFT){
                                                                                        fill(0);
                                                                                        rect(nowX,nowY,16,30);
                                                                                    }
                                                                                    else if(mousePressed &&                                                                                                                                     mouseButton==RIGHT){
                                                                                        fill(255);
                                                                                        rect(nowX,nowY,16,30);
                                                                                       }

                                                                                     }

加入圖片畫出殘影
PImage img; //declare outside
void setup(){
  size(500,600);
  img=loadImage("http://pm1.narvii.com/7065/030a867ffb28e32b52c9103c29bec8784851ccb2r5-1280-720_00.jpg");
}
void draw(){
  image(img,mouseX,mouseY,200,200);

                                                                                    } //Wrong, img draw() is not img setup()

打卡機
PImage imgBG;
int[][] table = new int[45][10];
void setup(){
  size(711,377);
  imgBG=loadImage("punch-card.jpg");
}
void draw(){
  background(imgBG);
  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<10;j++){
                                                                                          fill(0);
                                                                                          if(table[i][j]==1) rect(i*16,j*30,16,30);
                                                                                        }
                                                                                      }

                                                                                    }

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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