กันยายน 15, 2558

Lab4_books

int wink;
float spin;
void draw() {
  size(300, 400);
  background(0);  //colorBlack
  draw_book();
  if (keyPressed) {
    if (key==CODED) {
      if (keyCode==LEFT) spin+=PI/32;
      else if (keyCode==RIGHT) spin-=PI/32;
    }
  }
  fill(255);
  text("Pressed LEFT or RIGHT arrow.", 75, 350);
  fill(0);
}
void draw_book() {
  int posX=155, posY=150;
  float addPos=0,count=0;
  if (frameCount%50<=25) wink=1;
  else wink=0;
  //bones
  while (count<2) {
    translate(155, 150);
    rotate(spin+addPos);
    fill(255);  //colorWhite
    noStroke();
    beginShape();
    vertex(-90, -110);
    vertex(110, 90);
    vertex(110, 110);
    vertex(90, 110);
    vertex(-110, -90);
    vertex(-110, -110);
    endShape();
    beginShape();
    vertex(90, -110);
    vertex(-110, 90);
    vertex(-110, 110);
    vertex(-90, 110);
    vertex(110, -90);
    vertex(110, -110);
    endShape();
    ellipse(-100, -120, 30, 30);
    ellipse(-120, -100, 30, 30);
    ellipse(100, -120, 30, 30);
    ellipse(120, -100, 30, 30);
    ellipse(120, 100, 30, 30);
    ellipse(100, 120, 30, 30);
    ellipse(-100, 120, 30, 30);
    ellipse(-120, 100, 30, 30);
    rotate(-spin-addPos);
    translate(-155, -150);
    addPos=PI/4;
    count++;
  }
  //skull & hat
  stroke(0);
  strokeWeight(4);
  ellipse(posX, posY+90, 80, 90);
  fill(145, 55, 25);  //colorBrown
  arc(posX, posY, 170, 170, PI+PI/16, TWO_PI-PI/16);
  fill(255, 210, 50); //colorYellow
  arc(posX, posY, 170, 170, PI+PI/7, TWO_PI-PI/7);
  arc(posX, posY+30, 320, 115, PI+PI/5, TWO_PI-PI/5);
  fill(255); //colorWhite
  arc(posX, posY, 170, 170, 0, PI);
  arc(posX, posY, 170, 30, PI, TWO_PI);
  //detail
  fill(0);
  ellipse(posX, posY+60, 20, 20); //nose
  ellipse(posX+35, posY+25, 50, 50*wink); //R-eye
  ellipse(posX-35, posY+25, 50, 50*wink); //L-eye
  noFill();
  arc(posX, posY, 195, 195, HALF_PI-PI/8, HALF_PI+PI/8);
  arc(posX, posY, 220, 220, HALF_PI-PI/8+PI/48, HALF_PI+PI/8-PI/48);
  line(posX-20, posY+85, posX-23, posY+105);
  line(posX, posY+85, posX, posY+110);
  line(posX+20, posY+85, posX+23, posY+105);
  //book
  strokeWeight(3);
  stroke(100); //lncolorGray
  arc(5, 400, 16, 50, HALF_PI, 3*PI/2);
  line(8, 0, 8, 375);
  line(8, 375, 300, 375);
  line(7, 380, 300, 380);
  line(6, 385, 300, 385);
  line(5, 390, 300, 390);
  line(4, 395, 300, 395);
  wink++;
}
 

ไม่มีความคิดเห็น:

แสดงความคิดเห็น