2016年3月3日 星期四

WEEK02_02160136_陳威志

使用processing & leap motion來抓取手指末端
並且用手指來畫出彩色軌跡



程式碼:
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector [][] pt=new PVector[5][50];
void setup(){
  size(640,480,P3D);
  for(int f=0;f<5;f++){
 for(int i=0;i<50;i++)
  pt[f][i]=new PVector(0,0,0);
  }
 leap = new LeapMotion(this);
 colorMode(HSB,100);
}
void draw(){
  background(0);

   for(int f=0;f<5;f++){
  for(int i=49;i>0;i--){pt[f][i].x=pt[f][i-1].x;pt[f][i].y=pt[f][i-1].y;}
   }

  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<5;f++){
   stroke(f*20,100,100);
  for(int i=1;i<50;i++)
  line(pt[f][i].x,pt[f][i].y,pt[f][i].z,pt[f][i-1].x,pt[f][i-1].y,pt[f][i-1].z);
}
}

沒有留言:

張貼留言