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

Assignment 1


https://bitbucket.org/unthika_nongbua/assignment_template/raw/b7e6f77f904a15789b3b8d5cca9e2dcfedd7ce22/my_story.java

int door=250;
int smoke= 40;
int cloud = 100;
int page = 350;
int head = 80;
int eye1 = 250;
int eye2 = 150;
float emit1 = 100;
float emit2 = 100;
int upDown = 200;
int text = 26;
int [] decorate = {
  70, 450
};
int frame =0;
void setup () {
  size (500, 300);
}
void draw () {
  switch(frame) {
  case 0:
    cover();
    break;

  case 1:
    draw_house (smoke, door);
    smoke = smoke - 1;

    if (smoke < (-10)) {
      smoke = 40;
    }
    if (mouseX <= (width/2)) {
      door = door-1;
      if (door <= 50) {
        door=250;
      }
    } else {
      door=250;
    }
    break;
  case 2:
    int side = 500;
    int border = 250;
    magicCloud (side, cloud);
    cloud = cloud+1;
    theBook (page, border);

    if (cloud>150) {
      cloud = 100;
    }
    if (mouseX >= (width/2)) {
      page = 350;
    } else {
      page = 150;
      border = 0;
    }
    break;
  case 3:
    drawBody (head, eye1, eye2);
    head++;
    if (head == 100) {
      head = 80;
    }
    if (mouseX == width/2 || mouseY == 50) {
      fill (102);
      textSize (50);
      text ("Teddy", 50, 200);
    }
    eye1 = mouseX;
    eye2 = mouseY;
    break;
  case 4:
    some_snack (emit1, emit2, upDown, text);
    emit1=emit1+0.2;
    emit2=emit2-0.2;

    if (emit1 >= 105) {
      emit1 = 100;
    }
    if (emit2 < 95) {
      emit2 = 100;
    }
    if (mouseY >= (height/2)) {
      upDown = 500;
      emit1 = 300;
      text = 60;
      fill (255, 0, 0);
      textSize (60);
      text ("BIGGER", (width/2)-100, (height)-50);
    } else {
      upDown = 200;
      text = 26;
    }
    break;
  case 5:
    frame = 0;
  }
}
void cover () {
  background (255, 51, 102);
  fill (255);
  textSize (15);
  text (" Press the TAB Bottom to continue", 130, 250);
  textSize (25);
  text ("Unthika Nongbua", 150, 200);
  textSize (47);
  text (" My Story ", (width/2)-100, height/2);
  fill (255, 255, 0);
  noStroke ();
  ellipse (450, 250, 30, 30);
  for (int i =0; i<decorate.length; i++) {
    ellipse (decorate[i], 70, 50, 50);
    ellipse (decorate[i], 250, 30, 30);
  }
}
void draw_house (int smoke, int door) {
  background (255);
  noStroke ();
  fill (255, 153, 153);
  rect (50, 150, 400, 150);
  fill (153, 51, 0);
  triangle (480, 150, 20, 150, 250, 30);
  fill (153, 255, 255);
  quad ((width/2)-50, height, width/2+50, height, width/2+50, height-100, (width/2)-50, height-100);
  fill (255, 255, 0);
  quad ((width/2)-50, height, door+50, height, door+50, height-100, (width/2)-50, height-100);

  fill (0);
  ellipse (door+35, height-50, 30, 20);
  rect (100, 60, 50, 70);
  ellipse (110, smoke+8, 20, 10);
  ellipse (100, smoke-10, 30, 10);
  ellipse (75, smoke-25, 40, 10);
  textSize (47);
  text (" My Dream ", (width/2)-100, (height/2)-10);
  textSize (15);
  text (" Press the RIGHT Bottom to continue", 120, (height/2)+20);
}


void magicCloud (int side, int cloud) {
  background (255);
  noStroke ();
  fill (0, 204, 255);
  //cloud left
  ellipse (side-500, (height/2)+30, cloud-50, cloud-50);
  ellipse (side-490, (height/2)+80, cloud+20, cloud);
  ellipse (side-480, (height/2)+150, cloud+100, cloud+50);

  //cloud right
  ellipse (side, (height/2)+30, cloud-50, cloud-50);
  ellipse (side-10, (height/2)+80, cloud+20, cloud);
  ellipse (side-20, (height/2)+150, cloud+100, cloud+50);
}

void theBook (int page, int border) {
  fill (204, 153, 51);
  quad (width/2, (height/2)-100, width/2, (height/2)+50, (width/2)+100, (height/2)+50, (width/2)+100, (height/2)-100);

  fill (255, 51, 102);
  quad (width/2, (height/2)-100, width/2, (height/2)+50, page, (height/2)+50, page, (height/2)-100);

  stroke (153, 51, 0);
  strokeWeight (10);
  line (border, border-200, border, border-50);

  fill (204, 153, 51);
  textSize (15);
  text ("The Book", (width/2)+20, (height/2)-30);
  textSize (35);
  text (" My Hobby ", (width/2)-100, (height/2)-110);
  textSize (15);
  text (" Press the UP Bottom to continue", 120, (height/2)+90);
}

void drawBody(int head, int eye1, int eye2) {
  background (255);
  noStroke ();
  fill (102, 51, 0);
  ellipse((width/2)-30, (height/2)-90, 30, 40); //ears
  ellipse((width/2)+30, (height/2)-90, 30, 40);
  fill (255);
  ellipse((width/2)-30, (height/2)-85, 10, 20); //in ears
  ellipse((width/2)+30, (height/2)-85, 10, 20);
  fill (102, 51, 0);
  ellipse ((width/2)-10, (height/2)+100, 10, 70); //legs
  ellipse ((width/2)+10, (height/2)+100, 10, 70);
  rect ((width/2)+30, (height/2)+50, 15, 10, 10);//tail
  ellipse (width/2, (height/2)+30, 70, 100); //body
  fill (225, 225, 153);
  ellipse (width/2, (height/2)+30, 40, 70); //in body
  fill (51, 0, 0);
  ellipse ((width/2)-10, height-20, 20, 10); //feet
  ellipse ((width/2)+10, height-20, 20, 10);
  fill (102, 51, 0);
  ellipse (width/2, (height/2)-50, head, head); //haed
  noStroke ();
  fill (255);
  ellipse ((width/2)-15, (height/2)-60, 20, 25);//eyes
  ellipse ((width/2)+15, (height/2)-60, 20, 25);
  fill (0);
  ellipse (eye1-15, eye2-60, 10, 15);//in eyes
  ellipse (eye1+15, eye2-60, 10, 15);
  fill (225, 225, 153);
  arc((width/2), (height/2)-20, 40, 40, PI, 2*PI);//mouth
  arc((width/2), (height/2)-20, 40, 20, 0, PI);//mouth
  fill (153);
  ellipse (width/2, (height/2)-30, 25, 25); //nose
  stroke (102);
  strokeWeight (1.8);
  line (width/2, (height/2)-40, width/2, (height/2)-30);
  curve((width/2)-3, (height/2)-10, width/2, (height/2)-30, (width/2)-9, (height/2)-25, (width/2)-6, (height/2)-60);
  curve((width/2)+3, (height/2)-10, width/2, (height/2)-30, (width/2)+9, (height/2)-25, (width/2)+6, (height/2)-60);
  noStroke();
  fill (0);
  ellipse (width/2, (height/2)-40, 15, 10);
  stroke (0, 0, 255);
  strokeWeight (3);
  noStroke();
  strokeWeight (0);
  textSize (30);
  text (" I Happy ", (width/2)+70, (height/2)-50);
  textSize (15);
  text (" Press the LEFT Bottom to continue", 120, height-5);
  text ("You can take a look into", (width/2)+70, (height/2)-20);
  text ("the eyes of the bear", (width/2)+70, (height/2)-5);
  text ("position.", (width/2)+70, (height/2)+10);
}

void some_snack (float emit1, float emit2, int upDown, int text) {
  background (255);
  noStroke ();
  fill (0, 0, 255);
  textSize (15);
  text ("The last page.", (width/2)-50, height-35);
  text ("Press the Down Bottom to front cover", (width/2)-125, height-20);
  fill (0, 255, 0);
  ellipse (width/2, height/2, emit1+80, upDown);
  strokeWeight (40);
  stroke (0, 255, 0);
  line ((emit2*2), upDown-130, (emit1*3), upDown-130);
  line ((emit1*3), upDown+30, emit2*2, upDown+30);
  fill (0);
  textSize(text);
  text ("Some", (width/2)-50, (height/2)-30);
  text ("snack", (width/2), (height/2)+20);
  fill (0, 0, 255);
  textSize (35);
  text (" I Like ", (width/2)-50, 40);
}
void keyPressed() {
  frame++;
}

ดูการแสดงผลได้ใน :https://bitbucket.org/unthika_nongbua/assignment_template/src/b7e6f77f904a15789b3b8d5cca9e2dcfedd7ce22/my_story.java?at=default


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

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