Introduction
In this tutorial, you will be able to use Leap Motion sensor to create vectors. This tutorial shows capability to our “Wind [Motion] Chime” setup which is use Leap Motion to control the Wind Chime move up and down and make sounds.
Tutorial Parts List:
- Arduino UNO (1)
- Leap Motion (1)
Step 1
Go to website: https://www.leapmotion.com/setup?lang=en
Download “the Leap Motion Controller”
Install Leap Motion Controller
Step 2
Go to website: http://www.onformative.com/lab/leapmotionp5/
Download library “LeapMotionP5 archive v0.5”
Install the library
Step 3
Processing Code
Go to the “File” menu –> Examples drop down, you should be able to see the names of the new library that you’ve just installed. Find out “active_fingers”, and open up.
Copy the code
“import com.onformative.leap.LeapMotionP5;”
“import com.leapmotion.leap.Finger;”
to the very front of the new sketch
In the “active_fingers” example, Leap Motion could sense 5 fingers’ movement and draw ellipse.
In the new processing code, we use Leap Motion to create vectors.
Here’s the Sketch for the example: active_finger:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import com.onformative.leap.*; import com.leapmotion.leap.*; LeapMotionP5 leap; void setup() { size(600, 600, P3D); noFill(); stroke(255); leap = new LeapMotionP5(this); } void draw() { background(0); for (Finger f : leap.getFingerList()) { PVector position = leap.getTip(f); PVector velocity = leap.getVelocity(f); ellipse(position.x, position.y, 10, 10); line(position.x, position.y, position.x + velocity.x, position.y + velocity.y); } |
Here’s the Sketch for the “Leap Motion Wave”:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import igeo.IVec2; import com.onformative.leap.LeapMotionP5; import com.leapmotion.leap.Finger; float wid = 500; float hei = 500; int wnum = 50; int hnum = 50; grid[][] gs; lineWave line; IVec2 vReco; int count = 0; LeapMotionP5 leap; IVec2 dir = new IVec2(); void setup() { size((int)wid, (int)hei); leap = new LeapMotionP5(this); gs = new grid[wnum][hnum]; line = new lineWave(new IVec2(mouseX, mouseY), 0, 100); line.setWH(wid, hei); for (int i=0; i<wnum; i++) { for (int j=0; j<hnum; j++) { gs[i][j] = new grid(wid/wnum*i, hei/hnum*j, 0); } } vReco = new IVec2(); } void draw() { count ++; if (leap.getFingerList().size()>0) { PVector fingerPos = leap.getTip(leap.getFingerList().get(0)); dir = new IVec2(fingerPos.x-vReco.x, fingerPos.y-vReco.y); dir.unit(); if (dir.x!=0 && dir.y!=0) { line.resetDir(dir); } vReco = new IVec2(fingerPos.x, fingerPos.y); } line.time(0.1f); line.affect(gs); background(255); for (grid[] gg : gs) { for (grid g : gg) { g.draw(this); } } line.draw(this); line(width/2, height/2, width/2+(float)dir.x*100, height/2+(float)dir.y*100); } |