2016年3月3日 星期四

Week 02 : 手勢軌跡



import de.voidplus.leapmotion.*;
LeapMotion leap;

int PT_NO=100;
PVector[][] pt=new PVector[5][PT_NO];
void setup(){
  size(640,480,P3D);
  colorMode(HSB,100);
  background(0);
  for(int f=0;f<5;f++)
    for(int i=0;i<PT_NO;i++)pt[f][i]=new PVector(0,0,0);
  leap=new LeapMotion(this);
}
void drawStroke(PVector[][] pt){
  for(int f=0;f<pt.length;f++){  
    for(int i=1;i<pt[f].length;i++){
      stroke(f*20,100,100,100-100/pt[f].length*i);      
      line(pt[f][i].x,pt[f][i].y,pt[f][i-1].x,pt[f][i-1].y);
    }
  }
}
void draw(){
  background(0);
  for(Hand hand: leap.getHands()){
    for(Finger finger: hand.getFingers()){
        int f=finger.getType();
        PVector now =finger.getPosition();
        pt[f][0].x=now.x;
        pt[f][0].y=now.y;
      
    }
  }
  for(int f=0;f<pt.length;f++)
    for(int i=pt[f].length-1;i>0;i--){
      pt[f][i].x=pt[f][i-1].x;
      pt[f][i].y=pt[f][i-1].y;
    }
   
  drawStroke(pt);
}

沒有留言:

張貼留言