2014年5月19日 星期一

譚庚倫的第14周作業

1.做出出拳用隨機的方式,並且記錄動作的輸出事件
以下是程式碼
import SimpleOpenNI.*;
void setup()
{
  size(600, 400, P3D);
}

float ballz=0;
 float hookAngle=0;
int hooktype=0;
void draw()
{
  background(255);


if (hooktype==0)
  {
   println("hooking_right");
    pushMatrix();
    noStroke();
    lights();
    translate(300+sin(hookAngle)*200, 200, -cos(hookAngle)*200);
    fill(255, 0, 0);
    sphere(20);
    hookAngle+=0.1;
    
    if (hookAngle>=PI)
    {
    reset();
     
    }
 popMatrix();

  }
  if (hooktype==1)
  {
  
    println("hooking");
    pushMatrix();
    noStroke();
    lights();
    translate(300-sin(hookAngle)*200, 200, -cos(hookAngle)*200);
    fill(255, 0, 0);
    sphere(20);
    hookAngle+=0.1;

    if (hookAngle>=PI)
    {
      println("hookangle");
     reset();
    }
    popMatrix();
      
  }
  if (hooktype==2) {
   
    pushMatrix();
    noStroke();
    lights();
    translate(300, 200, ballz);
    sphere(28);
    println("Ballz"+ballz);
    ballz+=10;
    if (ballz==1000) 
    {
      println("hookball");
     reset();
   }
    popMatrix();
   
   
  }

  
}
void reset(){
    hookAngle=0;
    hooktype=int(random(3));
    ballz=0;
  }

沒有留言:

張貼留言