2015年5月18日 星期一

Week13

水果忍者



●畫出球&讓球拋起&重複再拋



code:


import SimpleOpenNI.*;
SimpleOpenNI openni;


class Fruit{
  float X, Y, VX, VY;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy;
  }


  void draw(){
    ellipse(x, y, 50, 50);
  }


  void update(){
    X+=VX;Y+=VY; VY+=1.98;
    if(X<-100) || X>740 || Y<-100 || Y>580{
      X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30);
    }
  }
}



Fruit fruit[]= new Fruit[20];



void setup(){
  size(640, 480);
  openni= new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i]= new Fruit(random(640), random(240), random(30)-15, -random(30));
}



void draw(){
  openni.update();
  image(openni.userImage(), 0, 0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }
}





photo:












滑鼠移動出現軌跡&滑鼠碰到球, 球變紅色


code:


import SimpleOpenNI.*;
SimpleOpenNI openni;

class Fruit{
  float X, Y, VX, VY;
  boolean dead= false;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy; dead= false;
  }


  void draw(){
    if(dead) fill(255, 0 , 0);
    else fill(255);
    ellipse(X, Y, 50, 50);
  }


  void update(){

    X+=VX;Y+=VY; VY+=1.98;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30); dead= false;
    }
    if(dist(X, Y, mouseX, mouseY)<50) dead= true;
  }

}



void mouseMoved(){
  strokeWeight(30); stroke(255, 0, 0); line(mouseX, mouseY, pmouseX, pmouseY);
  strokeWeight(1); stroke(0);
}



Fruit fruit[]= new Fruit[20];



void setup(){
  size(640, 480);
  openni= new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i]= new Fruit(random(640), random(240), random(30)-15, -random(30));
}



void draw(){
  openni.update();
  image(openni.userImage(), 0, 0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }
}




photo:








配合Kinect, 身體變藍色的人, 碰到球, 球變紅色



code:



import SimpleOpenNI.*;
SimpleOpenNI openni;
class Fruit{
  float X, Y, VX, VY;
  boolean dead= false;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy; dead= false;
  }


  void draw(){
    if(dead) fill(255, 0 , 0);
    else fill(255);
    ellipse(X, Y, 50, 50);
  }


  void update(){
    X+=VX;Y+=VY; VY+=1.98;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(30)-15; VY=-random(30); dead= false;
    }


    if(dist(X, Y, mouseX, mouseY)<50) dead= true;
    if(X>0 && X<640 && Y>0 && Y<480 && openni.userImage().pixels[int(X)+int(Y)*640]==color(0, 0, 255)) dead=true;
  }
}



void mouseMoved(){

  strokeWeight(30); stroke(255, 0, 0); line(mouseX, mouseY, pmouseX, pmouseY);
  strokeWeight(1); stroke(0);
}



Fruit fruit[]= new Fruit[20];


void setup(){
  size(640, 480);
  openni= new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i]= new Fruit(random(640), random(240), random(30)-15, -random(30));
}


void draw(){
  openni.update();
  image(openni.userImage(), 0, 0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }

}




photo:









切水果, 依照滑鼠切的方向方開



code:


import SimpleOpenNI.*;
SimpleOpenNI openni;


class Fruit{

  float X, Y, VX, VY, split=0, angle=0;
  boolean dead= false;
  Fruit(float x, float y, float vx, float vy){
    X=x; Y=y; VX=vx; VY=vy; dead= false;
  }


  void draw(){
    if(dead){
      fill(255, 0, 0);
      arc(X+split, Y, 50, 50, angle, angle+PI, CHORD);
      arc(X-split, Y, 50, 50, angle+PI, angle+PI*2, CHORD);
    }



    else {
      fill(255);
      ellipse(X, Y, 50, 50);
    }
  }


  void update(){
    X+=VX; Y+=VY; VY+=0.68;
    if(X<-100 || X>740 || Y<-100 || Y>580){
      X=random(640); Y=random(240); VX=random(10)-15; VY=-random(10); dead= false; split=0;
    }


    if(dead==false && dist(X, Y, mouseX, mouseY)<50){
      dead= true;
      angle= atan2(mouseY-pmouseY, mouseX-pmouseX);
    }

    if(dead==false && X>0 && X<640 && Y>0 && Y<480 && openni.userImage().pixels[int(X)+int(Y)*640]==color(0, 0, 255)){
      dead=true;
    }

    if(dead) split+=2;

  }
}



void mouseMoved(){
  strokeWeight(30); stroke(255, 0, 0); line(mouseX, mouseY, pmouseX, pmouseY);
  strokeWeight(1); stroke(0);
}



Fruit fruit[]= new Fruit[20];

void setup(){
  size(640, 480);
  openni= new SimpleOpenNI(this);
  openni.enableDepth();
  openni.enableUser();
  for(int i=0; i<20; i++)
    fruit[i]= new Fruit(random(640), random(240), random(10)-15, -random(10));
}


void draw(){
  openni.update();
  image(openni.userImage(), 0, 0);
  for(int i=0; i<20; i++){
    fruit[i].draw();
    fruit[i].update();
  }

}



photo:







沒有留言:

張貼留言