2015年3月9日 星期一

第二週


畫出手掌中心。
(先去Sketch>Library>Add librar,然後下載Leap Motion)
(下載好之後,去File>Example,打開e1_basic)

程式碼:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600,600, P3D);
  leap = new LeapMotion(this);
}
void draw(){
  background(255);
  for(Hand hand : leap.getHands()){
    hand.draw();
    PVector pos=hand.getPosition();
    translate(pos.x, pos.y);
    fill(255,0,0); box(50);
  }
}


-------------------------------------------------------------------------------------------------------------------------





畫出手指的關節。


程式碼:
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()){
    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 lp;

void setup(){
  size(800,600,P3D);
  lp=new LeapMotion(this);
}
void draw(){
 background(255);
  for(Hand hand :lp.getHands()){
    println("yaw:"+hand.getYaw());
    pushMatrix();
    translate(400,400);
    rotateY(-radians(hand.getYaw()));
    stroke(0);
    fill(0,100,50);
    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,255);sphere(20);
  popMatrix();
}









沒有留言:

張貼留言