2016年3月3日 星期四

Week 02 02160430 陳繁鑫

***LeapMotion函式庫只能在Processing2.2.1使用(未更新)***
重複上禮拜動作、作品欣賞。

Leap Motion 下載:https://www.leapmotion.com/setup

安裝完開啟,右下角綠色表示有偵測到LeapMotion



解壓縮Processing


開啟Processing,建立環境。

***程式必須在size()以下才能執行***


開啟調色盤,並選擇喜歡的顏色。



改變筆刷顏色(stroke(color))



新增PVector陣列儲存點資料


透過10條線表現漸層效果
for (int i=9; i>0; i--) {
    pt[i].x=pt[i-1].x;
    pt[i].y=pt[i-1].y;
    pt[i].z=pt[i-1].z;
  }
  pt[0].x=mouseX;
  pt[0].y=mouseY;
  for(int i=1;i<10;i++)
    line(pt[i].x, pt[i].y, pt[i].z, pt[i-1].x, pt[i-1].y, pt[i-1].z);

最新座標給舊座標,舊座標給更舊的座標......(ry
---------------------------------------------------------------------------------
匯入leapmotion函式庫並初始化


使用leapmotion函式庫抓取手部手指,並使用手指操作。




使用二維陣列抓取五根手指,並增加點數。




























getType()抓取不同手指


結果:


若要操作左右手須使用三維陣列
---------------------------------------------------------------------------------

更改後完整程式碼

import de.voidplus.leapmotion.*;
LeapMotion leap;
PVector [][] pt = new PVector[5][50];
void setup() {
  size(640, 480, P3D);
  for (int f=0; f<5; f++) {
    for (int i=0; i<50; i++) {
      pt[f][i]=new PVector (0, 0, 0);
    }
  }
  leap = new LeapMotion(this);
  colorMode(HSB, 100);
}

void draw() {
  background(0);
  for (int f=0; f<5; f++) {
    for (int i=49; i>0; i--) {
      pt[f][i].x=pt[f][i-1].x;
      pt[f][i].y=pt[f][i-1].y;
      pt[f][i].z=pt[f][i-1].z;
    }
  }
  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=0; f<5; f++) {
    stroke(f*20, 100, 100);
    for (int i=1; i<50; 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);
  }
}

---------------------------------------------------------------------------------


沒有留言:

張貼留言