Coder Social home page Coder Social logo

leapjs's Introduction

LeapJS

Welcome to the Leap JavaScript framework. This is intended for use with the Leap (https://www.leapmotion.com/).

Build Status

Installation

If you're using npm, you can use npm install leapjs.

Usage

LeapJS works from with Node.js or your browser.

From the browser

Include the leap.js script included at the root of this package, or, use the minified version provided at leap.min.js.

<script src="./leap.min.js"></script>

From node

Use the following:

var Leap = require('leapjs').Leap

Getting frames

To listen to the frame events, you can use the friendly Leap.loop function. This will auto-detect which type of event loop you can accept, and, call your callback with frames.

Leap.loop(function(frame) {
  // ... your code here
})

As well, you can call a special version of Leap.loop where you provide a second argument to the callback. This allows you to wait until you're ready to receieve further frame events. Here is an exmaple of this approach.

Leap.loop(function(frame, done) {
  // do things
  done() // if you don't invoke this, you won't get more events
})

Options

Using v0.7.5 of SDK on onwards, options can now be recognized by the connection.

Enabling gestures

Currently, the only recognized option is enabledGestures. This can be set to either true or false;

Passing options

Using the loop method, you can pass in options in the following way:

Leap.loop({enableGestures: true}, {
  // do things
});

To pass in options when constructing the controller, do the following:

var controller = new Leap.Controller({enableGestures: true});

Internals of the event loop

Leap.loop attempts to pick the right event loop to use. Within the background page of a Chrome extension, Chrome will not use the animationFrame loop. As well, in Node.js no animation event exists.

In general, browsers optimize the load of requestAnimationFrame based on load, element visibility, battery status, etc. Chrome has chosen to optimize this by omitting the functionality altogether in the background.js of its extensions.

To manually pick the event type you'd like to use, create a leap controller and listen for the appropriate event type, either frame or animationFrame.

Picking your own event type

var controller = new Leap.Controller();

// for the frame event
controller.on('frame', function() {
  console.log("hello frame")
})

// for the animationFrame event. this is only supported from within the browser
controller.on('animationFrame', function() {
  console.log("hello frame")
})
controller.connect()

Examples

Inside the examples directory are a few great examples. To get them running, do the following:

Node.js example

To run the node.js example, run node exmaples/node.js.

Development

You can build your own leap.js file by using make build. If you're doing any amount of development, you'll find it convenient to run make watch. This takes care of building leap.js for you on every edit. As well, you can both watch and running make watch-test.

Tests

There are currently rudamentary tests. To get them running, do the following:

  • Run npm install
  • Run make test

Or use make watch-test as noted above.

leapjs's People

Contributors

robbieongithub avatar joshbuddy avatar stutrek avatar barbagallo avatar ajacksified avatar saschagehlich avatar logotype avatar alexhung avatar bjnortier avatar juliangarnier avatar rpearson-catdevnull avatar wesbos avatar

Watchers

Jon Barker avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.