Lesson 4.1 – Basic Leap Examples
Using Gestures:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(800, 500);
background(255);
// leap = new LeapMotion(this).withGestures(); // with all gestures
leap = new LeapMotion(this).withGestures("swipe"); // Leap detects only swipe gestures.
}
void draw(){
}
// ----- SWIPE GESTURE -----
void leapOnSwipeGesture(SwipeGesture g, int state){
int id = g.getId();
PVector position_start = g.getStartPosition();
PVector position = g.getPosition();
switch(state){
case 1: // Start
break;
case 2: // Update
break;
case 3: // Stop
position.sub(position_start);
position.normalize();
if(position.x >= 0) {
println("towards right");
} else {
println("towards left");
}
break;
}
}
Finding hand positions:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(1000, 800);
leap = new LeapMotion(this);
}
void draw(){
background(255);
// ========= get hand locations from Leapmotion =========
for(Hand hand : leap.getHands()){
// ----- Variables -----
PVector hand_position = hand.getPosition();
boolean hand_is_left = hand.isLeft();
boolean hand_is_right = hand.isRight();
if(hand_is_left) {
// println("left"+hand_position);
fill(0,0,255);
ellipse(hand_position.x, hand_position.y, 16, 16);
}
if(hand_is_right) {
fill(255,0,0);
//println("right"+hand_position);
ellipse(hand_position.x, hand_position.y, 16, 16);
}
}
}