/LeapMotionP5

Leap Motion library for Processing including gesture support

Primary LanguageJava

LeapMotionP5

A Leap Motion Library for Processing

Working with all Processing versions and all operating systems (OSX, Windows), with the newest version of the leap motion sdk. Moreover it is including a variety of gestures. Just download the library archive at the bottom of this readme and extract it into the libraries folder of your processing sketchbook and your're ready to go.

API

List of all available methods:

LeapMotionP5(PApplet)

void start()
void stop()
void update()
void addGesture(String)

Frame getFrame()
Frame getLastFrame()
LinkedList getFrames()
LinkedList getFrames(int)

ArrayList getHandList()
ArrayList getHandList(Frame)
Hand getHand(int)
float getPitch(Hand)
float getRoll(Hand)
float getYaw(Hand)
PVector getDirection(Hand)
PVector getVelocity(Hand)
PVector getPosition(Hand)
PVector getNormal(Hand)
PVector getAcceleration(Hand)

ArrayList getPointableList()
ArrayList getPointableList(Frame)
ArrayList getPointableList(Hand)
Pointable getPointable(int)

ArrayList getToolList()
ArrayList getToolList(Frame)
ArrayList getToolList(Hand)
Tool getTool(int)

ArrayList getFingerList()
ArrayList getFingerList(Frame)
ArrayList getFingerList(Hand)
Finger getFinger(int)

PVector getTip(Pointable)
PVector getTip(Tool)
PVector getTip(Finger)

PVector getOrigin(Pointable)
PVector getOrigin(Tool)
PVector getOrigin(Finger)

PVector getVelocity(Pointable)
PVector getVelocity(Tool)
PVector getVelocity(Finger)

PVector getAcceleration(Pointable)
PVector getAcceleration(Tool)
PVector getAcceleration(Finger)

PVector getDirection(Pointable)
PVector getDirection(Tool)
PVector getDirection(Finger)

float getLength(Pointable)
float getLength(Tool)
float getLength(Finger)

float getWidth(Pointable)
float getWidth(Tool)
float getWidth(Finger)

Gesture Recognition

It's possible to use a vast variety of gestures with the leap motion in processing.

One finger gestures:

  • swipe left
  • swipe right
  • swipe up
  • swipe down
  • push
  • pull

Other:

  • onHandEnter
  • onHandLeave
  • onFingerEnter
  • onFingerLeave

One finger drawing gestures:

  • circle
  • triangle
  • rectangle
  • x
  • check
  • charet
  • zig-zag
  • arrow
  • leftsquarebracket
  • rightsquarebracket
  • leftcurlybrace
  • rightcurlybrace
  • v
  • delete
  • star
  • pigtail

Download

Download from here https://github.com/mrzl/LeapMotionP5/archive/master.zip extract the folder in the archive into your processing libraries folder and rename it from LeapMotionP5-master to LeapMotionP5. After that restart Processing and the library should be included. Check the examples within the library.

Examples

Basic Example

import com.onformative.leap.LeapMotionP5;
import com.leapmotion.leap.Finger;

LeapMotionP5 leap;

public void setup() {
  size(500, 500);
  leap = new LeapMotionP5(this);
}

public void draw() {
  background(0);
  fill(255);
  for (Finger finger : leap.getFingerList()) {
    PVector fingerPos = leap.getTip(finger);
    ellipse(fingerPos.x, fingerPos.y, 10, 10);
  }
}

public void stop() {
  leap.stop();
}

Gesture Recognition

import com.onformative.leap.LeapMotionP5;
import com.onformative.leap.LeapGestures;

LeapMotionP5 leap;
String lastGesture = "";

public void setup() {
  size(500, 500);
  textSize(30);

  leap = new LeapMotionP5(this);
  
  leap.addGesture(LeapGestures.SWIPE_LEFT);
  leap.addGesture(LeapGestures.SWIPE_RIGHT);
  leap.addGesture(LeapGestures.SWIPE_UP);
  leap.addGesture(LeapGestures.SWIPE_DOWN);
  //leap.addGesture(LeapGestures.ON_HAND_ENTER);
  //leap.addGesture(LeapGestures.ON_HAND_LEAVE);
  //leap.addGesture(LeapGestures.ON_FINGER_ENTER);
  //leap.addGesture(LeapGestures.ON_FINGER_LEAVE);
  //leap.addGesture(LeapGestures.PUSH);
  //leap.addGesture(LeapGestures.PULL);
  leap.addGesture(LeapGestures.CIRCLE);
  leap.addGesture(LeapGestures.TRIANGLE);
  leap.addGesture(LeapGestures.RECTANGLE);
  //leap.addGesture(LeapGestures.ZIG_ZAG);
  //leap.addGesture(LeapGestures.X);
  //leap.addGesture(LeapGestures.CHECK);
  //leap.addGesture(LeapGestures.CHARET);
  //leap.addGesture(LeapGestures.ARROW);
  //leap.addGesture(LeapGestures.LEFT_CURLY_BRACKET);
  //leap.addGesture(LeapGestures.RIGHT_CURLY_BRACKET);
  //leap.addGesture(LeapGestures.LEFT_SQUARE_BRACKET);
  //leap.addGesture(LeapGestures.RIGHT_SQUARE_BRACKET);
  //leap.addGesture(LeapGestures.V);
  //leap.addGesture(LeapGestures.DELETE);
  //leap.addGesture(LeapGestures.STAR);
  //leap.addGesture(LeapGestures.PIGTAIL);
  
  leap.start();
}

public void draw() {
  background(0);
  leap.gestures.one.draw();
  leap.update();
  text(lastGesture, 30, 30);
}

public void gestureRecognized(String gesture) {
  lastGesture = gesture;
}

License

LeapMotionP5 library for Processing.
Copyright (c) 2012-2013 held jointly by the individual authors.

LeapMotionP5 library for Processing is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

LeapMotionP5 library for Processing is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with LeapMotionP5 library for Processing.  If not, see http://www.gnu.org/licenses/.
Leap Developer SDK.
Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved.

NOTICE: This developer release of Leap Motion, Inc. software is confidential
and intended for very limited distribution. Parties using this software must
accept the SDK Agreement prior to obtaining this software and related tools.
This software is subject to copyright.
OneDollar Unistroke Recognizer
Copyright 2012, Darius Morawiec

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.