2019年9月19日 星期四

week02

互動技術

用滑鼠畫畫:
void setup(){//Start()
  size(800,300);
}
void draw(){//Update()
  rect(mouseX,mouseY,50,20);利用滑鼠的移動位置做為起始點

}










void setup(){
  size(800,300);//共計長45格寬10格
  for(int x=0;x<800;x=x+16){ //每格長寬為16*30
    for(int y=0;y<300;y=y+30){
      rect(x,y,16,30);
    }
  }
}
void draw(){
  int nowX=mouseX/16*16 ,nowY=mouseY/30*30;//鼠標移動,鼠標移動到那一格的座標為亂數但因在那一格裡因此除以長寬得知在第幾格乘上長寬得知該格的座標範圍,得到新的座標
  fill(0);//將新座標的格子塗上顏色
  rect(nowX,nowY,16,30);

}









void setup(){
  size(800,300);
  for(int x=0;x<800;x=x+16){
    for(int y=0;y<300;y=y+30){
      rect(x,y,16,30);
    }
  }
}
void draw(){
  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;//在外面宣告,讓兩個函數都可以找到img
void setup(){
  size(500,500);
  img=loadImage("kk.jpg");//將圖片下載
}
void draw(){
  image(img,mouseX,mouseY,100,100);

}









PImage img;
int [][] table=new int[45][10];//使用矩陣
void setup(){
  size(711,377);//要符合圖片的大小
  img=loadImage("card.jpg");
}
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<10;j++){
      fill(0);
      if(table[i][j]==1) rect(i*16,j*30,16,30);
    }
  }

}

沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

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