2015年3月9日 星期一

week02 控制方塊




控制方塊*2
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
   size(800, 600,P3D);
  leap=new LeapMotion(this);
}
void draw(){
  background (255);
   for(Hand hand : leap.getHands())
{
  //println("yaw:"+hand.getYaw());
  println("pitch:"+hand.getPitch());
  //println("roll:"+hand.getRoll());
  pushMatrix();
  translate(hand.getPosition().x,hand.getPosition().y);
  rotateZ(radians(hand.getPitch()));
  rotateY(-radians(hand.getPitch()));
  stroke(0);
  fill(255);
  box(100);
  popMatrix();
 
    hand.draw();
    myDraw(hand.getPosition());
    myDraw(hand.getThumb().getPosition());
    myDraw(hand.getIndexFinger().getPosition());
    myDraw(hand.getMiddleFinger().getPosition());
    myDraw(hand.getRingFinger().getPosition());
    myDraw(hand.getPinkyFinger().getPosition());
}
}
void myDraw(PVector pos){
  pushMatrix();
    translate(pos.x,pos.y);
    fill(255,0,0); sphere(20);
     popMatrix();

}

分辨左右手
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
   size(800, 600,P3D);
  leap=new LeapMotion(this);
}
void draw(){
  background (255);
  println(leap.getHands().size());
  fill(255,0,0);
  textSize(40);
  {
   for(Hand hand : leap.getHands())
{
  if(hand.isRight()){
    text("right"+hand.getFingers().size(),400,300);
  }
  else text("left"+hand.getFingers().size(),200,300);
}
  }
}

分辨左右手的手指數(剪刀石頭布)
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
   size(800, 600,P3D);
  leap=new LeapMotion(this); 
}
void draw(){
  background (255);
  println(leap.getHands().size());
  fill(255,0,0);
  textSize(40);
  {
   for(Hand hand : leap.getHands())
{
  if(hand.isRight()){
    text("right"+hand.getOutstrechtedFingers().size(),400,300);
  }
  else text("left"+hand.getOutstrechtedFingers().size(),200,300);
}
  }
}

猜拳

PImage img0,img2,img5;
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
   size(800, 600,P3D);
  leap=new LeapMotion(this); 
  img0=loadImage("b.png");
  img2=loadImage("a.png");
  img5=loadImage("c.png");
}
void draw(){
  background (255);
  println(leap.getHands().size());
  fill(255,0,0);
  textSize(40);
  {
   for(Hand hand : leap.getHands())
{
  int n=hand.getOutstrechtedFingers().size();
  if(hand.isRight()){
    if(n==0) image(img0,400,300);
    else if(n<=2) image(img2,400,300);
    else image(img5,400,300);
   // text("right"+hand.getOutstrechtedFingers().size(),400,300);
  }
  else if (n==0) image(img0,400,300);
  else if(n<=2) image(img2,400,300);
  else image(img5,400,300);
  //else text("left"+hand.getOutstrechtedFingers().size(),200,300);
}
  }
}




沒有留言:

張貼留言