วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558

LAB 3 Bird_movement

void setup(){
  size(600,600);

}

//set base value
int wingMovement=0; // make movement wing like it up and down
int count=-200; //limit wing hight
int roadMovement=0; // make movement road like it turn down
int countLine=0; //limit movement road

void draw(){
  background(0);
 
  // call function
  movement();
  road(300,0,roadMovement);
  draw_bird(mouseX,mouseY,wingMovement);
 

}



// make function draw bird
void draw_bird(int X,int Y,int wingMovement){
  draw_body(X,Y,100);
  draw_wing(X,Y,wingMovement);
}


// make function draw body bird
void draw_body(int X,int Y,int R){
  fill(0,0,255);
  ellipse(X,Y,R,R);
  stroke(255,0,0);
  eye(X,Y);
}
 
// make function draw eye bird
void eye(int X,int Y){
  point(X-20,Y);
  point(X+20,Y);
}

// make function draw wing bird
void draw_wing(int X,int Y,int movement){
  noFill();
  strokeWeight(5);
  stroke(0,255,50);
  line(X-50,Y,X-250-movement/5,Y+movement);
  line(X+50,Y,X+250+movement/5,Y+movement);
}

//make function draw road
void road(int X,int Y,int movement){
  fill(255);
  stroke(255);
  background(0);
  line(X-100,Y,X-100,Y+600);
  line(X+100,Y,X+100,Y+600);
  strokeWeight(10);
  line(X,Y-100+movement,X,Y+movement);
  line(X,Y+100+movement,X,Y+200+movement);
  line(X,Y+300+movement,X,Y+400+movement);
  line(X,Y-300+movement,X,Y-200+movement);
  line(X,Y-500+movement,X,Y-400+movement);
}

//set rule movement
void movement(){
  count++;
  if(countLine>=0){
    roadMovement++;
    countLine++;
  }
  if(countLine==600){
    countLine=0;
    roadMovement=0;
  }
 
 
 
  if(count==400){
    count=-400;
  }
 
 
 
  if(count>=0){
    wingMovement++;
    frameRate(40+frameCount/2);
  }
  if(count<0){
    wingMovement--;
    frameRate(40+frameCount/2);
  }
  if(frameCount==800){
    frameCount=0;
  }
}


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

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