How to use leapjs - 10 common examples

To help you get started, we’ve selected a few leapjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wellsjo / LeapMotion-Hue-Controller / app / app.js View on Github external
startLeapController: function() {
        var controller = new leap.Controller(),
        lightSetInterval = null,
        updatingLights = false,
        state = {
            "on": false, // lights on: true/false
            "bri": null, // brightness: 0-255
            "hue": null, // hue: 0-65535
            "sat": 255   // always set to 255 for full color
        };

        hue.updateLights(state);

        console.log('Put your hand over the leapmotion to turn the lights on...');

        // continuous loop from the Leap Motion
        controller.on('frame', function(frame) {
github leapmotion / javascript / v2 / kitchen / index.js View on Github external
if (this.directionsIndex < this.directions.length) this.directionsIndex++;
  },

  speakingDone: function(){
    // note -this needs to be updated for concurrent async speech
    //this.speech = null;
  },

  loudnessError: function(){}

};


speaker = new Speaker(recipe);

Leap.loopController.on('gesture', function(gesture){
  //if (gesture.type != 'swipe' && gesture.type != 'update') console.log('u', gesture.id);
  if (gesture.type != 'swipe' || gesture.state != 'start') return;

  var hand = Leap.loopController.frame().hand(gesture.handIds[0]);

  if (hand.grabStrength > 0.7){
    console.log('rejecting due to high grabStrength: ' + hand.grabStrength);
    return
  }

  if (
    Math.abs(gesture.direction[0]) > Math.abs(gesture.direction[1]) &&
    Math.abs(gesture.direction[0]) > Math.abs(gesture.direction[2])
  ){
    speaker.handleGesture(gesture);
  }
github mimic-sussex / sema / src / interfaces / leapMotion.js View on Github external
constructor() {
    
    this.options = {
      host: '127.0.0.1',
      port: 6437,
      enableGestures: false,
      background: false,
      optimizeHMD: false,
      frameEventName: 'animationFrame',
      useAllPlugins: false
    }


    Leap.loop(function(frame){
      console.log(frame.hands.length);
    });

    // this.controller = new Leap.Controller();
    // this.controller = new Leap.Controller(options);
    // controller.connect();
  }
github rhansby / leap-gamepad / main.js View on Github external
// Camera benhavior variables
var sensitivityX = 0.09;
var sensitivityY = 0.0725;

var centerX = 0;
var x_box_width = 12.5;

var centerY = 205;
var y_box_width = 15;

var x_safe = [centerX - x_box_width, centerX + x_box_width]
var y_safe = [centerY - y_box_width, centerY + y_box_width];

//Main event loop
var controller = new Leap.Controller({ loopWhileDisconnected: true });
controller.setBackground(true);
controller.loop(function(frame) {
    if (frame.hands.length === 0) {
        bangEventEmitted = false;
        return;
    }

    var hand = frame.hands[0];

    //Update camera position
    var posX = hand.indexFinger.stabilizedTipPosition[0];
    var posY = hand.indexFinger.stabilizedTipPosition[1];

    if (posX > x_safe[0] && posX < x_safe[1]) {
        posX = 0;
    }
github ytham / robotarm / robotarm.js View on Github external
var MIN_Y = 0;
var MIN_Z = 0;
var MAX_Z = 800;

// How many past frames to cache for smoothing; slows down response time with a higher number
var SMOOTHING_FRAMES = 10;

/*
 * Need to set up 4 servos: shoulder, elbow, claw, and base
 * Use inverse kinematics equation on servoShoulder & servoElbow
 * Use fingerDistance to rotate servoClaw to desired position
 * Servos must be placed on the Arduino's PWM pins
 */

// Leap motion controller
var controller = new Leap.Controller();

// Main Leap frame loop
controller.on('frame', function(frame) {
  // Hand position controls the robot arm position
  if(frame.hands.length > 0) {
    handPosition = frame.hands[0].palmPosition;

    // Offset z to always keep the value positive
    frame.hands[0].palmPosition[1] -= 150;
    frame.hands[0].palmPosition[2] = 200 + (-1*frame.hands[0].palmPosition[2]);

    var smoothedInput = smoothInput(handPosition);
    smoothingQueue(handPosition);

    // Restrict certain inputs to prevent physical damage
    // These values should be changed depending on your arm design
github glenmurphy / route / modules / leap / leap.js View on Github external
function Leap(data) {
  this.threshold = data.threshold || 10;

  var controllerOptions = {
    host: data.host || '127.0.0.1',
    port: data.port || 6437,
    enableGestures: data.enableGestures || false,
    enableHeartbeat: data.enableHeartbeat || true,
    heartbeatInterval: data.heartbeatInterval || 100,
    requestProtocolVersion: data.requestProtocolVersion || 3
  };
  this.controller = new Leapjs.Controller(controllerOptions);

  this.controller.on('frame', this.handleFrame.bind(this));

  if (controllerOptions.enableGestures) {
    this.controller.on('gesture', this.handleGesture.bind(this));
  }

  this.controller.on('ready', function() {
    console.log("Leap ready");
  });
  this.controller.on('connect', function() {
    console.log("Leap connected");
  });
  this.controller.on('disconnect', function() {
    console.log("Leap disconnected");
  });
github charliegerard / leap_sphero / index.js View on Github external
var controlSphero = function(sphero) {

  var controller = new Leap.Controller({frameEventName:'deviceFrame', enableGestures:true});

  //Debugging console messages to make sure the Leap Motion is connected and working.
  controller.on('connect', function() {
    console.log('connected to leap motion');
  });
  controller.on('ready', function() {
    console.log('ready');
  });
  controller.on('focus', function() {
    console.log('focus?');
  });
  controller.on('deviceConnected', function() {
    console.log('device connected');
  });
  controller.on('deviceDisconnected', function() {
    console.log('device disconnected');
github charliegerard / leap_sphero / my_modules / sphero / index.js View on Github external
var controlSphero = function(spheroBall) {

    var controller = Leap.loop({frameEventName:'deviceFrame', enableGestures:true});

    controller.on('connect', function() {
    	console.log('connected to leap motion');
    });
    controller.on('ready', function() {
        console.log('ready');
    });
    controller.on('deviceStreaming', function() {
        console.log('device connected');
    });
    controller.on('deviceStopped', function() {
        console.log('device disconnected');
    });
    controller.on('frame', function(frame) {
      if(frame.hands[0]){
        var hand = frame.hands[0];
github charliegerard / leap_sphero / sphero_module / index.js View on Github external
const initLeapMotionConnection = () => {
  controller = Leap.loop({frameEventName:'deviceFrame', enableGestures:true});
  console.log('waiting for Leap Motion connection...');

  controller.connect();

  controller.on('connect', () => {
    console.log('connected to leap motion');
  });
  controller.on('ready', () => {
      console.log('ready');
  });
  controller.on('deviceStreaming', () => {
      console.log('device connected');
  });
  controller.on('deviceStopped', () => {
      console.log('device disconnected');
  });
github leapmotion / javascript / v2 / kitchen / index.js View on Github external
Leap.loopController.on('gesture', function(gesture){
  //if (gesture.type != 'swipe' && gesture.type != 'update') console.log('u', gesture.id);
  if (gesture.type != 'swipe' || gesture.state != 'start') return;

  var hand = Leap.loopController.frame().hand(gesture.handIds[0]);

  if (hand.grabStrength > 0.7){
    console.log('rejecting due to high grabStrength: ' + hand.grabStrength);
    return
  }

  if (
    Math.abs(gesture.direction[0]) > Math.abs(gesture.direction[1]) &&
    Math.abs(gesture.direction[0]) > Math.abs(gesture.direction[2])
  ){
    speaker.handleGesture(gesture);
  }

});

leapjs

JavaScript client for the Leap Motion Controller

Apache-2.0
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis