วันพุธที่ 7 พฤษภาคม พ.ศ. 2557

Animation basketball

Animation basketball
คำสั่ง

int y = 0;
int check_hight = 0;

void setup() {
  size(500, 500);
  background(255, 255, 255, 255);
  frameRate(15);
  draw_human();
}

void draw_bas(int y){ //draw bas
  fill(234,120,12);
  noStroke();
  ellipse(160,175+y,30,30);

}

void draw_human(){ //draw human
  fill(0);
  stroke(5);
  ellipse(100,100,100,100);
  line(100, 150, 160, 160);
  line(100,150,100,200);
  line(85,200,125,200);
  line(85,200,80,220);
  line(125,200,130,220);
  fill(137,234,12);
  noStroke();
  rect(0,220,500,10);
  
}

void draw(){
  background(255);
  draw_human();
  draw_bas(y);
  
  if(check_hight == 0){ //check hight maximum
    y = y+1;
  }
  else{
    y = y-1;
  }
  if(y==30){
    check_hight = 1;  //check hight lower
  }
  if( y == 0){
    check_hight = 0; //check hight maximum
  }
}

จากคำสั่งเมื่อรันโปรแกรมจะเป็นรูปคนเล่นลูกบาสเกตบอลขึ้นลง โดยจากคำสั่งจะมีการบวก ค่า y ทีละ 1 รูปลูกบาสก็จะขึ้นไปเรื่อยๆ เมื่อค่า y ครบ 30 ค่า y จะมีการลบทีละ 1 รูปลูกบาสก็จะลงไปเรื่อยดังรูป




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

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