===
Contributed library to use the Leap Motion in Processing.
The Leap detects and tracks hands, fingers and finger-like tools. The device operates in an intimate proximity with high precision and tracking frame rate.
The Leap software analyzes the objects observed in the device field of view. It recognizes hands, fingers, and tools, reporting both discrete positions and motion. The Leap field of view is an inverted pyramid centered on the device. The effective range of the Leap extends from approximately 25 to 600 millimeters above the device (1 inch to 2 feet).
Either you use the import manager of Processing (Sketch > Import library ... > Add library ... > Filter: "Leap Motion").
Or you download, unzip and copy the extracted LeapMotionForProcessing folder into the libraries folder of your Processing sketches. The reference and examples are stored in the LeapMotionForProcessing directory. For further help you can read the instructions by Daniel Shiffman.
- Running Leap Motion Software v2 (2.3.1+31549)
System:
- OSX (Mac OS 10.7 and higher)
- Linux (not tested yet, but it should work) (Ubuntu Linux 12.04 LTS and Ubuntu 13.04 Raring Ringtail)
- Windows (not tested yet, but x86 and x64 should work) (Windows 7 and 8)
Processing version:
- 3.2.3
- 3.1.2
- 3.1.1
- 3.0.2
- 3.0.1
- 3.0a5
To use an older version of Processing examine the release section:
- 2.2.1
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0b9
- 2.0b8
- 2.0b7
Leap Motion Software version:
- 2.3.1+31549
- 2.2.5+26752
- 2.2.4+26750
- 2.2.3+25971
- 2.2.1+24116
- 2.2.0+23475
- 2.1.6+23110
- 2.1.5+22699
- 2.0.5+18024 beta
- 2.0.4+17546 beta
- 2.0.3+17004 beta
- 2.0.2+16391 beta
- 2.0.1+15831 beta
- 2.0.0+13819 beta
The following example shows the basic data access:
importde.voidplus.leapmotion.*;
// ======================================================// Table of Contents:// ├─ 1. Callbacks// ├─ 2. Hand// ├─ 3. Arms// ├─ 4. Fingers// ├─ 5. Bones// ├─ 6. Tools// └─ 7. Devices// ======================================================LeapMotionleap;
voidsetup() {
size(800, 500);
background(255);
// ...leap = newLeapMotion(this);
}
// ======================================================// 1. CallbacksvoidleapOnInit() {
// println("Leap Motion Init");
}
voidleapOnConnect() {
// println("Leap Motion Connect");
}
voidleapOnFrame() {
// println("Leap Motion Frame");
}
voidleapOnDisconnect() {
// println("Leap Motion Disconnect");
}
voidleapOnExit() {
// println("Leap Motion Exit");
}
voiddraw() {
background(255);
// ...intfps = leap.getFrameRate();
for (Handhand : leap.getHands ()) {
// ==================================================// 2. HandinthandId = hand.getId();
PVectorhandPosition = hand.getPosition();
PVectorhandStabilized = hand.getStabilizedPosition();
PVectorhandDirection = hand.getDirection();
PVectorhandDynamics = hand.getDynamics();
floathandRoll = hand.getRoll();
floathandPitch = hand.getPitch();
floathandYaw = hand.getYaw();
booleanhandIsLeft = hand.isLeft();
booleanhandIsRight = hand.isRight();
floathandGrab = hand.getGrabStrength();
floathandPinch = hand.getPinchStrength();
floathandTime = hand.getTimeVisible();
PVectorspherePosition = hand.getSpherePosition();
floatsphereRadius = hand.getSphereRadius();
// --------------------------------------------------// Drawinghand.draw();
// ==================================================// 3. Armif (hand.hasArm()) {
Armarm = hand.getArm();
floatarmWidth = arm.getWidth();
PVectorarmWristPos = arm.getWristPosition();
PVectorarmElbowPos = arm.getElbowPosition();
}
// ==================================================// 4. FingerFingerfingerThumb = hand.getThumb();
// or hand.getFinger("thumb");// or hand.getFinger(0);FingerfingerIndex = hand.getIndexFinger();
// or hand.getFinger("index");// or hand.getFinger(1);FingerfingerMiddle = hand.getMiddleFinger();
// or hand.getFinger("middle");// or hand.getFinger(2);FingerfingerRing = hand.getRingFinger();
// or hand.getFinger("ring");// or hand.getFinger(3);FingerfingerPink = hand.getPinkyFinger();
// or hand.getFinger("pinky");// or hand.getFinger(4); for (Fingerfinger : hand.getFingers()) {
// or hand.getOutstretchedFingers();// or hand.getOutstretchedFingersByAngle();intfingerId = finger.getId();
PVectorfingerPosition = finger.getPosition();
PVectorfingerStabilized = finger.getStabilizedPosition();
PVectorfingerVelocity = finger.getVelocity();
PVectorfingerDirection = finger.getDirection();
floatfingerTime = finger.getTimeVisible();
// ------------------------------------------------// Drawing// Drawing:// finger.draw(); // Executes drawBones() and drawJoints()// finger.drawBones();// finger.drawJoints();// ------------------------------------------------// Selectionswitch(finger.getType()) {
case0:
// System.out.println("thumb");break;
case1:
// System.out.println("index");break;
case2:
// System.out.println("middle");break;
case3:
// System.out.println("ring");break;
case4:
// System.out.println("pinky");break;
}
// ================================================// 5. Bones// --------// https://developer.leapmotion.com/documentation/java/devguide/Leap_Overview.html#Layer_1BoneboneDistal = finger.getDistalBone();
// or finger.get("distal");// or finger.getBone(0);BoneboneIntermediate = finger.getIntermediateBone();
// or finger.get("intermediate");// or finger.getBone(1);BoneboneProximal = finger.getProximalBone();
// or finger.get("proximal");// or finger.getBone(2);BoneboneMetacarpal = finger.getMetacarpalBone();
// or finger.get("metacarpal");// or finger.getBone(3);// ------------------------------------------------// Touch emulationinttouchZone = finger.getTouchZone();
floattouchDistance = finger.getTouchDistance();
switch(touchZone) {
case -1: // Nonebreak;
case0: // Hovering// println("Hovering (#" + fingerId + "): " + touchDistance);break;
case1: // Touching// println("Touching (#" + fingerId + ")");break;
}
}
// ==================================================// 6. Toolsfor (Tooltool : hand.getTools()) {
inttoolId = tool.getId();
PVectortoolPosition = tool.getPosition();
PVectortoolStabilized = tool.getStabilizedPosition();
PVectortoolVelocity = tool.getVelocity();
PVectortoolDirection = tool.getDirection();
floattoolTime = tool.getTimeVisible();
// ------------------------------------------------// Drawing:// tool.draw();// ------------------------------------------------// Touch emulationinttouchZone = tool.getTouchZone();
floattouchDistance = tool.getTouchDistance();
switch(touchZone) {
case -1: // Nonebreak;
case0: // Hovering// println("Hovering (#" + toolId + "): " + touchDistance);break;
case1: // Touching// println("Touching (#" + toolId + ")");break;
}
}
}
// ====================================================// 7. Devicesfor (Devicedevice : leap.getDevices()) {
floatdeviceHorizontalViewAngle = device.getHorizontalViewAngle();
floatdeviceVericalViewAngle = device.getVerticalViewAngle();
floatdeviceRange = device.getRange();
}
}Source: Leap Motion
The following example shows how to recognize predefined gestures:
importde.voidplus.leapmotion.*;
// ======================================================// Table of Contents:// ├─ 1. Swipe Gesture// ├─ 2. Circle Gesture// ├─ 3. Screen Tap Gesture// └─ 4. Key Tap Gesture// ======================================================LeapMotionleap;
voidsetup(){
size(800, 500);
background(255);
// ...leap = newLeapMotion(this).allowGestures(); // All gestures// leap = new LeapMotion(this).allowGestures("circle, swipe, screen_tap, key_tap");// leap = new LeapMotion(this).allowGestures("swipe"); // Leap detects only swipe gestures
}
voiddraw(){
background(255);
// ...
}
// ======================================================// 1. Swipe GesturevoidleapOnSwipeGesture(SwipeGestureg, intstate){
intid = g.getId();
Fingerfinger = g.getFinger();
PVectorposition = g.getPosition();
PVectorpositionStart = g.getStartPosition();
PVectordirection = g.getDirection();
floatspeed = g.getSpeed();
longduration = g.getDuration();
floatdurationSeconds = g.getDurationInSeconds();
switch(state){
case1: // Startbreak;
case2: // Updatebreak;
case3: // Stopprintln("SwipeGesture: " + id);
break;
}
}
// ======================================================// 2. Circle GesturevoidleapOnCircleGesture(CircleGestureg, intstate){
intid = g.getId();
Fingerfinger = g.getFinger();
PVectorpositionCenter = g.getCenter();
floatradius = g.getRadius();
floatprogress = g.getProgress();
longduration = g.getDuration();
floatdurationSeconds = g.getDurationInSeconds();
intdirection = g.getDirection();
switch(state){
case1: // Startbreak;
case2: // Updatebreak;
case3: // Stopprintln("CircleGesture: " + id);
break;
}
switch(direction){
case0: // Anticlockwise/Left gesturebreak;
case1: // Clockwise/Right gesturebreak;
}
}
// ======================================================// 3. Screen Tap GesturevoidleapOnScreenTapGesture(ScreenTapGestureg){
intid = g.getId();
Fingerfinger = g.getFinger();
PVectorposition = g.getPosition();
PVectordirection = g.getDirection();
longduration = g.getDuration();
floatdurationSeconds = g.getDurationInSeconds();
println("ScreenTapGesture: " + id);
}
// ======================================================// 4. Key Tap GesturevoidleapOnKeyTapGesture(KeyTapGestureg){
intid = g.getId();
Fingerfinger = g.getFinger();
PVectorposition = g.getPosition();
PVectordirection = g.getDirection();
longduration = g.getDuration();
floatdurationSeconds = g.getDurationInSeconds();
println("KeyTapGesture: " + id);
}Furthermore you have access to the raw camera images:
importde.voidplus.leapmotion.*;
LeapMotionleap;
voidsetup(){
size(640, 480);
background(255); leap = newLeapMotion(this);
}
voiddraw(){
background(255);
if (leap.hasImages()) {
for (Imagecamera : leap.getImages()) {
if (camera.isLeft()) {
// left cameraimage(camera, 0, 0);
} else {
// right cameraimage(camera, 0, camera.getHeight());
}
}
}
}You can find the changes in the release section.
Don't be shy and feel free to contact me on Twitter or Gitter.
The library is Open Source Software released under the license.

