- LeapMotion Setup
LeapMotion App Store
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(640,480);
leap = new LeapMotion(this);
}
void draw(){
background(255);
for (Hand hand : leap.getHands()){
hand.draw();
}
}
- LeapMotion Finger
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(640,480);
leap = new LeapMotion(this);
}
void draw(){
background(255);
for (Hand hand : leap.getHands()){
//hand.draw();
for (Finger finger : hand.getFingers()){
finger.draw();
}
}
}
- hand grab coin
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(640,480);
leap = new LeapMotion(this);
}
float coinX=320, coinY=0, coinVX=0, coinVY=3;
int score=0;
void draw(){
background(255);
coinY += coinVY;
fill(255,255,0); ellipse(coinX, coinY, 60, 60);
if(coinY>480){
coinY=0;
coinX=random(640);
}
for (Hand hand : leap.getHands()){
//hand.draw();
PVector pos = hand.getPosition();
//println(pos);
fill(220,0,0); ellipse(pos.x, pos.y, 100,100);
if ( dist(pos.x, pos.y, coinX, coinY) < 100 ){
score += 10;
coinY=0;
coinX=random(640);
}
}
fill(255,0,0);
textSize(30);
text("Score:" + score, 400, 100);
}
- 彈力球
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(640,480);
leap = new LeapMotion(this);
}
float coinX=320, coinY=0, coinVX=0, coinVY=3;
int score=0;
void draw(){
background(255);
coinY += coinVY;
coinX += coinVX;
if(coinX<0 || coinX>640) coinVX = -coinVX;
if(coinY<0 || coinY>480) coinVY = -coinVY;
fill(255,255,0); ellipse(coinX, coinY, 60, 60);
for (Hand hand : leap.getHands()){
//hand.draw();
PVector pos = hand.getPosition();
//println(pos);
fill(220,0,0); ellipse(pos.x, pos.y, 100,100);
if ( dist(pos.x, pos.y, coinX, coinY) < 100 ){
score += 10;
PVector dir = new PVector (coinX - pos.x, coinY - pos.y)'
dir.normalize(); // 無函式無法執行
dir.mult(3);
coinVX = dir.x;
coinVY = dir.y;
}
}
fill(255,0,0);
textSize(30);
text("Score:" + score, 400, 100);
}
沒有留言:
張貼留言