2013年9月16日 星期一

Week02 簡尉倫

1.試 for 迴圈
void setup(){
    size(600,400);
}
void draw (){
   for (int x = 0 ; x<600 ; x+=100){
       for (int y = 0 ; y < 400 ; y +=100){
             rect (x,y,100,100);
       }
   }
}
執行結果:











2 找rect()函式,並嘗試劃出和老師不同的圖
void setup(){
    size(600,400);
}
void draw (){
   for (int x = 0 ; x<600 ; x+=100){
       for (int y = 0 ; y < 400 ; y +=100){
             rect (x,y,100,100);
             triangle(x + 50 ,y ,x,y+100,x+100,y+100 );
             rect (x + 25 ,y+50,50,50);
             ellipse(x + 50 , y + 75 ,50 ,50);
       }
   }
}

執行結果:










3. 試著填上顏色 fill()是填充顏色,stroke()是筆的顏色
void setup() {
  size(600, 400);
}
void draw () {
  for (int x = 0 ; x<600 ; x+=100) {
    for (int y = 0 ; y < 400 ; y +=100) {
      fill (128, 0, 0);
      rect (x, y, 100, 100);
      fill (128, 128, 0,128);
      triangle(x + 50, y, x, y+100, x+100, y+100 );
      fill (0, 0,128);
      rect (x + 25, y+50, 50, 50);
      fill (0, 128, 0);
      ellipse(x + 50, y + 75, 50, 50);
    }
  }
}

執行結果:










4. 加上一點滑鼠的互動!可以利用mouseX及mosueY的值,來進行色彩繽紛的運算

void setup() {
  size(600, 400);
}
void draw () {
  for (int x = 0 ; x<600 ; x+=100) {
    for (int y = 0 ; y < 400 ; y +=100) {
      fill (128, 0, 0);
      rect (x, y, 100, 100);
      fill (128, 128, 0);
      triangle(x + 50, y, x, y+100, x+100, y+100 );
      fill (0, 0,128);
      rect (x + 25, y+50, 50, 50);
      fill (0, 128, 0,dist(x,y,mouseX,mouseY));
      ellipse(x + 50, y + 75, 50, 50);
    }
  }
}

執行結果:












5. 亂數random(數字上界 來設定初始的亂數值)

color [][] Color = new color [6][4];
void setup() {
  size(600, 400);
    for (int x = 0 ; x<600 ; x+=100) {
      for (int y = 0 ; y < 400 ; y +=100) {
      Color[x/100][y/100] = color(random(256),random(256),random(256));
      }
    }
}
void draw () {
  for (int x = 0 ; x<600 ; x+=100) {
    for (int y = 0 ; y < 400 ; y +=100) {
      fill (128, 0, 0);
      rect (x, y, 100, 100);
      fill (128, 128, 0);
      triangle(x + 50, y, x, y+100, x+100, y+100 );
      fill (Color[x/100][y/100]);
      rect (x + 25, y+50, 50, 50);
      fill (0, 128, 0,dist(x,y,mouseX,mouseY));
      ellipse(x + 50, y + 75, 50, 50);
    }
  }
}

執行結果:













心得:對於現在上課的速度感覺還好,只是自身對於一些圖形方面的感覺很差不是很會用。

沒有留言:

張貼留言