##課堂練習目標
1. 剪刀石頭布
2. 期中作品構想
##實作
先寫圖片載入,試試能不能顯示
安裝LEAP Motion相關函式庫
Sketch→Import Library→Add Library...→在搜尋打上"LEAP"
→選擇安裝 Leap Motion for Processing
安裝好後開啟範例程式碼
File→Examples...→最底下Cintributed Libraries→Leap Motion for Processing
→選第一個範例 e1_basic
修改程式碼
加入圖片宣告、來源
加入判斷式,讀到0~5個點分別要對應的圖片
hand_position語法,抓手的x、y座標
並讓圖片跟著手的座標跑
測試
=====程式碼=====
import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage img0,img2,img5;////STAP1
void setup(){
size(800, 500, P3D);
background(255);
noStroke(); fill(50);
// ...
leap = new LeapMotion(this);
////STAP2
img0=loadImage("http://i.imgur.com/ekPNgYi.jpg");
img2=loadImage("http://i.imgur.com/Oq8a9kT.jpg");
img5=loadImage("http://i.imgur.com/F5GXMqq.jpg");
imageMode(CENTER);
////STAP2
}
void draw(){
background(255);
// ...
int fps = leap.getFrameRate();
// HANDS
for(Hand hand : leap.getHands()){
////STAP3
/*int n=hand.countFingers();
if(n==0||n==1) image(img0,0,0);
if(n==2||n==3) image(img2,0,0);
if(n==5||n==4) image(img5,0,0); */
////STAP3
hand.draw();
int hand_id = hand.getId();
PVector hand_position = hand.getPosition();
PVector hand_stabilized = hand.getStabilizedPosition();
////STAP4
println("X:"+hand_position.x +"Y:"+hand_position.y);
int n=hand.countFingers();
if(n==0||n==1) image(img0,hand_position.x,hand_position.y);
if(n==2||n==3) image(img2,hand_position.x,hand_position.y);
if(n==5||n==4) image(img5,hand_position.x,hand_position.y);
////STAP4
PVector hand_direction = hand.getDirection();
PVector hand_dynamics = hand.getDynamics();
float hand_roll = hand.getRoll();
float hand_pitch = hand.getPitch();
float hand_yaw = hand.getYaw();
float hand_time = hand.getTimeVisible();
PVector sphere_position = hand.getSpherePosition();
float sphere_radius = hand.getSphereRadius();
// FINGERS
for(Finger finger : hand.getFingers()){
// Basics
finger.draw();
int finger_id = finger.getId();
PVector finger_position = finger.getPosition();
PVector finger_stabilized = finger.getStabilizedPosition();
PVector finger_velocity = finger.getVelocity();
PVector finger_direction = finger.getDirection();
float finger_time = finger.getTimeVisible();
// Touch Emulation
int touch_zone = finger.getTouchZone();
float touch_distance = finger.getTouchDistance();
switch(touch_zone){
case -1: // None
break;
case 0: // Hovering
// println("Hovering (#"+finger_id+"): "+touch_distance);
break;
case 1: // Touching
// println("Touching (#"+finger_id+")");
break;
}
}
// TOOLS
for(Tool tool : hand.getTools()){
// Basics
tool.draw();
int tool_id = tool.getId();
PVector tool_position = tool.getPosition();
PVector tool_stabilized = tool.getStabilizedPosition();
PVector tool_velocity = tool.getVelocity();
PVector tool_direction = tool.getDirection();
float tool_time = tool.getTimeVisible();
// Touch Emulation
int touch_zone = tool.getTouchZone();
float touch_distance = tool.getTouchDistance();
switch(touch_zone){
case -1: // None
break;
case 0: // Hovering
// println("Hovering (#"+tool_id+"): "+touch_distance);
break;
case 1: // Touching
// println("Touching (#"+tool_id+")");
break;
}
}
}
// DEVICES
// for(Device device : leap.getDevices()){
// float device_horizontal_view_angle = device.getHorizontalViewAngle();
// float device_verical_view_angle = device.getVerticalViewAngle();
// float device_range = device.getRange();
// }
}
void leapOnInit(){
// println("Leap Motion Init");
}
void leapOnConnect(){
// println("Leap Motion Connect");
}
void leapOnFrame(){
// println("Leap Motion Frame");
}
void leapOnDisconnect(){
// println("Leap Motion Disconnect");
}
void leapOnExit(){
// println("Leap Motion Exit");
}



沒有留言:
張貼留言