9 กันยายน 2558

Lab3 Flying bird

float wing_y;
int size_draw = 50;
boolean w_up;
boolean w_down;
void setup() {
  size(400, 500);
  background(255);
  mouseX=width/2;
  mouseY=height/2;
  w_up = true;
}

void draw() {
  background(255);
  draw_bird(mouseX, mouseY, size_draw);
  if (w_up == true) {
    if (mouseY<=100)wing_y-= size_draw*0.30;
    if (mouseY>100&&mouseY<=200)wing_y-= size_draw*0.20;
    if (mouseY>200&&mouseY<=300)wing_y-= size_draw*0.15;
    if (mouseY>300&&mouseY<=400)wing_y-= size_draw*0.10;
    if (mouseY>400&&mouseY<=500)wing_y-= size_draw*0.07;
    if (wing_y <= -(size_draw*0.5)) {
      w_up = false;
      w_down = true;
    }
  }
  if (w_down == true) {
    if (mouseY<=100)wing_y+= size_draw*0.30;
    if (mouseY>100&&mouseY<=200)wing_y+= size_draw*0.20;
    if (mouseY>200&&mouseY<=300)wing_y+= size_draw*0.15;
    if (mouseY>300&&mouseY<=400)wing_y+= size_draw*0.10;
    if (mouseY>400&&mouseY<=500)wing_y+= size_draw*0.07;
    if (wing_y >= (size_draw*0.5)) {
      w_up = true;
      w_down = false;
    }
  }
  if (keyCode==UP) {
    size_draw++;
    if (size_draw>=110)size_draw=110;
  }
  if (keyCode==DOWN) {
    size_draw--;
    if (size_draw<=50)size_draw=50;
  }
}

void draw_bird(int mouse_x, int mouse_y, int s_draw) {
  fill(#D30327);
  strokeWeight(s_draw*0.2);
  line(mouse_x, mouse_y-(s_draw*0.5), mouse_x-(s_draw*1.3), mouse_y+wing_y-(s_draw*0.5));
  line(mouse_x, mouse_y-(s_draw*0.5), mouse_x+(s_draw*1.3), mouse_y+wing_y-(s_draw*0.5));
  strokeWeight(s_draw*0.05);
  ellipse(mouse_x, mouse_y-(s_draw*0.5), s_draw, s_draw);
  strokeWeight(1);
  fill(255);
  ellipse(mouse_x-(s_draw*0.22), mouse_y-(s_draw*0.6), s_draw*0.3, s_draw*0.35);
  ellipse(mouse_x+(s_draw*0.22), mouse_y-(s_draw*0.6), s_draw*0.3, s_draw*0.35);
  fill(0);
  ellipse(mouse_x-(s_draw*0.22), mouse_y-(s_draw*0.6), s_draw*0.1, s_draw*0.1);
  ellipse(mouse_x+(s_draw*0.22), mouse_y-(s_draw*0.6), s_draw*0.1, s_draw*0.1);
  fill(#F9BC09);
  triangle(mouse_x-(s_draw*0.17), mouse_y-(s_draw*0.35), mouse_x+(s_draw*0.17),
    mouse_y-(s_draw*0.35), mouse_x, mouse_y-(s_draw*0.05));
}

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

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