用手指畫畫


五根手指頭
import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector [][] pt = new PVector[5][100];
void setup(){
size(640,480,P3D);
for(int f=0;f<5;f++){
for(int i=0;i<100;i++)pt[f][i] = new PVector(0,0,0);
}
leap = new LeapMotion(this);
colorMode(HSB,150);
}
void draw(){
background(0);
for(int f=0;f<5;f++){
for(int i=99;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=1;f<5;f++){
stroke(f*20,100,100);
for(int i=1;i<100;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);
}
}
import de.voidplus.leapmotion.*;
PVector [][]fingerPosition = new PVector[5][10];
LeapMotion leap;
void setup(){
size(640,480);
leap = new LeapMotion(this);
for(int f=0;f<5;f++)for(int i=0;i<10;i++)fingerPosition[f][i]= new PVector(0,0,0);
}
void draw(){
background(255);
LeapmotionSetup();
drawFinger();
}
//////////////////////////////////////////
void LeapmotionSetup(){
int fps = leap.getFrameRate();
for(Hand hand : leap.getHands ()){
for(Finger finger : hand.getFingers()){
switch(finger.getType()){
case 0:
fingerPosition[0][0] = finger.getPosition();
break;
case 1:
fingerPosition[1][0] = finger.getPosition();
break;
case 2:
fingerPosition[2][0] = finger.getPosition();
break;
case 3:
fingerPosition[3][0] = finger.getPosition();
break;
case 4:
fingerPosition[4][0] = finger.getPosition();
break;
}
}
}
}
//////////
void drawFinger(){
for(int f=0;f<5;f++)
for(int i=9;i>0;i--){
fingerPosition[f][i].x = fingerPosition[f][i-1].x;
fingerPosition[f][i].y = fingerPosition[f][i-1].y;
fingerPosition[f][i].z = fingerPosition[f][i-1].z;
}
for(int f=0;f<5;f++)
for(int i=0;i<9;i++){
strokeWeight(fingerPosition[f][i].z*30/50+1);
stroke(255,0,0,100-i*10);
line(fingerPosition[f][i+1].x,fingerPosition[f][i+1].y,fingerPosition[f][i].x,fingerPosition[f][i].y);
}
}
沒有留言:
張貼留言