上週課堂練習
加上方塊 讓方塊跟著手一起移動
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();
PVector pos = hand.getPosition();
translate(pos.x,pos.y);
fill(255,0,0);
box(100);
}
}
讓圓球跟著手指移動
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();
}
控制物體轉動
上下左右轉動
兩隻手一起控制
Yaw 左右轉動
Pitch 上下轉動
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()){
println("yaw:"+hand.getYaw()); // 印出數值
pushMatrix();
translate(hand.getPosition().x,hand.getPosition().y);
rotateZ(radians(hand.getPitch())); // 對Z軸旋轉
rotateY(-radians(hand.getYaw())); // 對Y軸轉動
stroke(0);fill(0,255,0);
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,0);
sphere(20);
popMatrix();
}
數左右手手指數量
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup() {
size(800, 600, P3D);
leap = new LeapMotion(this);
}
void draw(){
background(255);
fill(0,0,255);
textSize(40);
for(Hand hand : leap.getHands()){
if(hand.isRight()){
text("right" + hand.getOutstrechtedFingers().size(),400,300);
}
else
text("left" + hand.getOutstrechtedFingers().size(),200,300);
}
}
剪刀石頭布
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup() {
size(800, 600, P3D);
leap = new LeapMotion(this);
img0=loadImage("01.jpg");
img2=loadImage("02.jpg");
img5=loadImage("03.jpg");
}
void draw(){
background(255);
fill(0,0,255);
textSize(40);
for(Hand hand : leap.getHands()){
int n= hand.getOutstrechtedFingers().size();
if(hand.isRight()){
if(n==0) image(img0,400,300);
else if(n<=2) image(img2,400,300);
else image(img5,400,300);
}
else
if(n==0) image(img0,200,300);
else if(n<=2) image(img2,200,300);
else image(img5,200,300);
}
}
沒有留言:
張貼留言