2013年9月22日 星期日

Week03 陳奕汎

1.試著劃出棋盤
void setup ()
{
  size(800,800) ;
}
void draw ()
{
  background (#FFE3A5) ;
  noFill() ;
  strokeWeight (5) ;
  rect (50 , 50 , 700 , 700) ;
  strokeWeight (1) ;
  for ( int i = 0 ; i < 10 ; i++ )
  {
    line( 50 , 50+i*70 , 750 , 50+i*70) ;
    line( 50+i*70 , 50 , 50+i*70 , 750) ;
  }
}


2.追蹤滑鼠座標並對其棋格
int nowX , nowY ;
void setup ()
{
  size(800,800) ; //設定視窗大小
}
void draw ()
{
  background (#FFE3A5) ; //設定背景顏色
  noFill() ; //設定無填滿
  strokeWeight (5) ; // 設定線條粗細
  rect (50 , 50 , 700 , 700) ;
  strokeWeight (1) ;
  for ( int i = 0 ; i < 10 ; i++ )  // 畫出棋盤
  {
    line( 50 , 50+i*70 , 750 , 50+i*70) ;
    line( 50+i*70 , 50 , 50+i*70 , 750) ;
  }
  fill(255 , 0 , 0 ) ; //追蹤滑鼠座標並對其棋格
  rect ( nowX*70 + 50 , nowY*70 + 50 , 70 , 70) ;
}

void mouseMoved ()
{
  nowX = (mouseX -50 ) / 70 ;
  nowY = (mouseY -50) / 70 ;
}


3.試著將棋格改變顏色
int nowX , nowY ;
int [][] array = new int [10][10] ;  //宣告一個陣列
void setup ()
{
  size(800,800) ; //設定視窗大小
}
void draw ()
{
  background (#FFE3A5) ; //設定背景顏色
  noFill() ; //設定無填滿
  strokeWeight (5) ; // 設定線條粗細
  rect (50 , 50 , 700 , 700) ;
  strokeWeight (1) ;
  for ( int i = 0 ; i < 10 ; i++ )  // 畫出棋盤
  {
    line( 50 , 50+i*70 , 750 , 50+i*70) ;
    line( 50+i*70 , 50 , 50+i*70 , 750) ;
  }
  fill(255 , 0 , 0 ) ; //追蹤滑鼠座標並對其棋格
  rect ( nowX*70 + 50 , nowY*70 + 50 , 70 , 70) ;
  fill(0,0,255) ;  // 將棋格改成藍色
  for ( int i = 0 ; i < 10 ; i++ )  // 利用雙層for迴圈來改變棋格的顏色
  {
    for ( int j = 0 ; j < 10 ; j++ )
    {
      if (array[i][j] == 1 ) rect ( i*70+50 , j*70+50 , 70 , 70) ;  // 將滑鼠所在的棋格更改顏色
    }
  }

}

void mousePressed()   // 建立滑鼠的事件
{
  array[nowX][nowY] = 1 ;
}

void mouseMoved ()
{
  nowX = (mouseX -50 ) / 70 ;
  nowY = (mouseY -50) / 70 ;
}

4.將棋子放置於正確的位置上
int nowX , nowY ;
int mycolor = 1 ;
int [][] array = new int [10][10] ;  //宣告一個陣列
void setup ()
{
  size(800,800) ; //設定視窗大小
}
void draw ()
{
  background (#FFE3A5) ; //設定背景顏色
  noFill() ; //設定無填滿
  strokeWeight (5) ; // 設定線條粗細
  rect (50 , 50 , 700 , 700) ;
  strokeWeight (1) ;
  for ( int i = 0 ; i < 10 ; i++ )  // 畫出棋盤
  {
    line( 50 , 50+i*70 , 750 , 50+i*70) ;
    line( 50+i*70 , 50 , 50+i*70 , 750) ;
  }
  fill(255 , 0 , 0 ) ; //追蹤滑鼠座標並對其棋格
  noFill() ;
  rect ( nowX*70 + 85 , nowY*70 + 85 , 70 , 70) ;
    // 將棋格改成藍色
  for ( int i = 0 ; i < 10 ; i++ )  // 利用雙層for迴圈來改變棋格的顏色
  {
    for ( int j = 0 ; j < 10 ; j++ )
    {
      if (array[i][j] == 1 ) { fill(255) ; ellipse ( i*70+120 , j*70+120 , 70 , 70) ;}  // 將滑鼠所在的棋格更改顏色
      if (array[i][j] == 2 ) { fill(0) ; ellipse ( i*70+120 , j*70+120 , 70 , 70 ) ;}
    }
  }
 
}

void mousePressed()   // 建立滑鼠的事件
{
  array[nowX][nowY] = mycolor ;
  if (mycolor == 1 ) mycolor = 2 ;  //顏色可以互換
  else if(mycolor == 2 ) mycolor = 1 ;
}

void mouseMoved ()
{
  nowX = (mouseX -85) / 70 ;
  nowY = (mouseY -85) / 70 ;
}

沒有留言:

張貼留言