今日體驗:Leap motion
實際操作影片
今日程式:processing+leapmotion
step1:添加leap motion到library
開啟範本執行
step2: import 撰寫者的程式
step3: 只抓finger的動作
step4: 寫一個接金幣遊戲
程式碼:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(800,500,P3D); //設定場景 *加入~P3D(leapMotion)
leap=new LeapMotion(this);
}
float coinX=240, coinY=0, coinVX=0, coinVY=3; //設定浮點數 讓金幣隨機掉下
int score=0; // 設置分數機制
void draw(){
background(255); //設定背景
coinY += coinVY; // 設定金幣掉下
fill(255,0,0); ellipse(coinX, coinY, 60,60);
if(coinY>480) {
coinY=0;
coinX=random(640);
}
for(Hand hand : leap.getHands()){ //利用leapMotion感應手位置
//hand.draw();
PVector pos = hand.getPosition();
//println(pos);
fill(255,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(0,255,0);
textSize(40);
text("Score:" + score, 500,100);
}
沒有留言:
張貼留言