วันอังคารที่ 2 กันยายน พ.ศ. 2557

Lab 2 - Pencil

ถ้าให้ผมวาดดินสอ ผมจะไม่วาดดินสอธรรมดา แต่ผมจะวาดดินสอ RAINBOWWWWW !!



void setup(){
  background(255);
  size(500,500);
  frameRate(60);
}
int n=0;
void draw(){
  background(255);
  DrawPencil(mouseX,mouseY,n);
  n = second()%7;
}

void DrawPencil(float RefX,float RefY,int nColor){
  //variable draw pencil
  float WPencil,HPencil;
  float HHeadPencil;
  //assign
  WPencil=40;
  HPencil=300;
  HHeadPencil=35;
  //draw head pencil
  fill(252,200,86);
  triangle(RefX,RefY,RefX-(WPencil/2),RefY-HHeadPencil,RefX+(WPencil/2),RefY-HHeadPencil);
  fill(0);
  triangle(RefX,RefY,RefX-(WPencil/(2*3)),RefY-(HHeadPencil/3),RefX+(WPencil/(2*3)),RefY-(HHeadPencil/3));
  //draw handle pencil
  fill(PickColor(nColor));
  rect(RefX-(WPencil/2),RefY-HHeadPencil-HPencil,WPencil/3,HPencil);
  fill(PickColor(nColor+1));
  rect(RefX-(WPencil/2)+(WPencil/3),RefY-HHeadPencil-HPencil,WPencil/3,HPencil);
  fill(PickColor(nColor+2));
  rect(RefX-(WPencil/2)+(2*WPencil/3),RefY-HHeadPencil-HPencil,WPencil/3,HPencil);
}

color PickColor(int Choose){
  color ReturnColor=color(0);
  switch(Choose){
    case 0:
      ReturnColor = color(#FF0000);
      break;
    case 1:
      ReturnColor = color(#FFff00);
      break;
    case 2:
      ReturnColor = color(#00ff00);
      break;
    case 3:
      ReturnColor = color(#00ffff);
      break;
    case 4:
      ReturnColor = color(#0000ff);
      break;
    case 5:
      ReturnColor = color(#FF00ff);
      break;
    case 6:
      ReturnColor = color(#FF0000);
      break;
    case 7:
      ReturnColor = color(#FFff00);
      break;
    case 8:
      ReturnColor = color(#00ff00);
      break;
    case 9:
      ReturnColor = color(#00ffff);
      break;
  }
  return ReturnColor;
}