2013年9月22日 星期日

Week03


利用:畫線跟選取顏色的功能畫出棋盤面的格子
void setup(){
  size(800,800);
}
void draw() {
  background(#F0D079);
  noFill();
  strokeWeight(6);
  rect(50,50,700,700);
  strokeWeight(1);
  for(int i=0;i<9;i++){
    line(50,50+i*80,750,50+i*80);
    line(50+i*80,50,50+i*80,750);
  }
加入搭配滑鼠的使用
int nowX,nowY;
void setup(){
  size(800,800);
}
void draw() {
  background(#F0D079);
  noFill();
  strokeWeight(6);
  rect(50,50,700,700);
  strokeWeight(1);
  for(int i=0;i<9;i++){
    line(50,50+i*80,750,50+i*80);
    line(50+i*80,50,50+i*80,750);
  }
  fill(255,0,0);
  rect(nowX*80+50,nowY*80+50,80,80);

void mouseMoved(){
  nowX = (mouseX-50)/80;
  nowY = (mouseY-50)/80;
  print("mouseX: "+mouseX + "mouseY: "+"nowX: "+nowX+ " nowY:"+nowY);
}
經修正後出現整齊的格子
int nowX,nowY;
int[][] array = new int [10][10];// 1.宣告陣列
void setup(){
  size(1000,1000);
}
void draw() {
  background(#F0D079);
  noFill();
  strokeWeight(6);
  rect(50,50,800,800);
  strokeWeight(1);
  for(int i=0;i<=10;i++){
    line(50,50+i*80,850,50+i*80);
    line(50+i*80,50,50+i*80,850);
  }
  fill(255,0,0);
  ellipse(nowX*80+50,nowY*80+50,80,80);
  fill(0);// 配黑色
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      if(array[i][j]==1) rect(i*80+50,j*80+50,80,80);
    }
  }
void mousePressed(){
  array[nowX][nowY]=1;
}
void mouseMoved(){
  nowX = (mouseX-50)/80;
  nowY = (mouseY-50)/80;
  print("mouseX: "+mouseX + "mouseY: "+"nowX: "+nowX+ " nowY:"+nowY);
}

心得:關於老師教的程式跟之前的電腦圖學比較起來速度剛好

比較容易理解吸收的也比較OK




沒有留言:

張貼留言