npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leapmotion-ts

v2.2.4

Published

TypeScript framework for Leap Motion.

Downloads

22

Readme

This is the TypeScript framework for working with Leap Motion.

Leap Motion is a motion-control software and hardware company developing the world's most powerful and sensitive 3D motion-control and motion-sensing technology.

leapmotion.com

TypeScript is a free and open source programming language developed by Microsoft. TypeScript adds optional types, classes, interfaces and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript.

typescriptlang.org

Quick start

Clone the repo, git clone git://github.com/logotype/LeapMotionTS.git.

Import the library and create an instance of the Controller class. What you'll get from the LEAPMOTION_FRAME handler is a Frame instance, with strongly typed properties such as Hands, Pointables, Direction, Gestures and more:

import Leap = require('../LeapMotionTS');
var controller:Leap.Controller = new Leap.Controller();
controller.addEventListener(Leap.LeapEvent.LEAPMOTION_CONNECTED, (event:Leap.LeapEvent) => {
    controller.enableGesture(Leap.Type.TYPE_CIRCLE, true);
    controller.enableGesture(Leap.Type.TYPE_SWIPE, true);
    controller.enableGesture(Leap.Type.TYPE_SCREEN_TAP, true);
    controller.enableGesture(Leap.Type.TYPE_KEY_TAP, true);
});
controller.addEventListener(Leap.LeapEvent.LEAPMOTION_FRAME, (event:Leap.LeapEvent) => {
    var frame:Leap.Frame = event.frame;
    console.log("Frame id:" + frame.id + ", timestamp:" + frame.timestamp + ", hands:" + frame.hands.length + ", fingers:" + frame.fingers.length + ", tools:" + frame.tools.length + ", gestures:" + frame.gestures().length);

    if (frame.hands.length > 0) {
        // Get the first hand
        var hand:Leap.Hand = frame.hands[0];

        // Check if the hand has any fingers
        var fingers:Leap.Finger[] = hand.fingers;
        if (fingers.length > 0) {
            // Calculate the hand's average finger tip position
            var avgPos:Leap.Vector3 = Leap.Vector3.zero();
            for (var i:number = 0; i < fingers.length; i++)
                avgPos = avgPos.plus((<Leap.Finger>fingers[i]).tipPosition);

            avgPos = avgPos.divide(fingers.length);
            console.log("Hand has " + fingers.length + " fingers, average finger tip position:" + avgPos);
        }

        // Get the hand's sphere radius and palm position
        console.log("Hand sphere radius:" + hand.sphereRadius + " mm, palm position:" + hand.palmPosition);

        // Get the hand's normal vector and direction
        var normal:Leap.Vector3 = hand.palmNormal;
        var direction:Leap.Vector3 = hand.direction;

        // Calculate the hand's pitch, roll, and yaw angles
        console.log("Hand pitch:" + Leap.LeapUtil.toDegrees(direction.pitch) + " degrees, " + "roll:" + Leap.LeapUtil.toDegrees(normal.roll) + " degrees, " + "yaw:" + Leap.LeapUtil.toDegrees(direction.yaw) + " degrees\n");
    }

    var gestures:Leap.Gesture[] = frame.gestures();
    for (var i:number = 0; i < gestures.length; i++) {
        var gesture:Leap.Gesture = gestures[i];

        switch (gesture.type) {
            case Leap.Type.TYPE_CIRCLE:
                var circle:Leap.CircleGesture = <Leap.CircleGesture>gesture;

                // Calculate clock direction using the angle between circle normal and pointable
                var clockwiseness:string;
                if (circle.pointable.direction.angleTo(circle.normal) <= Math.PI / 4) {
                    // Clockwise if angle is less than 90 degrees
                    clockwiseness = "clockwise";
                } else {
                    clockwiseness = "counterclockwise";
                }

                // Calculate angle swept since last frame
                var sweptAngle:number = 0;
                if (circle.state != Leap.State.STATE_START) {
                    var previousGesture:Leap.Gesture = controller.frame(1).gesture(circle.id);
                    if (previousGesture.isValid()) {
                        var previousUpdate:Leap.CircleGesture = (<Leap.CircleGesture>controller.frame(1).gesture(circle.id));
                        sweptAngle = (circle.progress - previousUpdate.progress) * 2 * Math.PI;
                    }
                }
                console.log("Circle id:" + circle.id + ", " + circle.state + ", progress:" + circle.progress + ", radius:" + circle.radius + ", angle:" + Leap.LeapUtil.toDegrees(sweptAngle) + ", " + clockwiseness);
                break;
            case Leap.Type.TYPE_SWIPE:
                var swipe:Leap.SwipeGesture = <Leap.SwipeGesture>gesture;
                console.log("Swipe id:" + swipe.id + ", " + swipe.state + ", position:" + swipe.position + ", direction:" + swipe.direction + ", speed:" + swipe.speed);
                break;
            case Leap.Type.TYPE_SCREEN_TAP:
                var screenTap:Leap.ScreenTapGesture = <Leap.ScreenTapGesture>gesture;
                console.log("Screen Tap id:" + screenTap.id + ", " + screenTap.state + ", position:" + screenTap.position + ", direction:" + screenTap.direction);
                break;
            case Leap.Type.TYPE_KEY_TAP:
                var keyTap:Leap.KeyTapGesture = <Leap.KeyTapGesture>gesture;
                console.log("Key Tap id:" + keyTap.id + ", " + keyTap.state + ", position:" + keyTap.position + ", direction:" + keyTap.direction);
                break;
        }
    }
});

Example output:

Frame id:1125277, timestamp:14800590398, hands:1, fingers:5, tools:0, gestures:5
Hand has 5 fingers, average finger tip position:[Vector3 x:4.767591999999996 y:129.5072 z:-28.39772]
Hand sphere radius:136.979 mm, palm position:[Vector3 x:19.067 y:127.976 z:42.0272]
Hand pitch:6.500235603666339 degrees, roll:6.0708401144239925 degrees, yaw:-9.621146044782972 degrees
Circle id:27, 2, progress:3.92605, radius:43.2705, angle:13.417199999999967, counterclockwise
Circle id:25, 2, progress:3.90497, radius:40.3004, angle:13.489199999999961, counterclockwise

Optionally, you can simply call controller.frame() e.g. in your main loop, or implement the Listener interface for callbacks.

Authors

Victor Norgren

  • http://twitter.com/logotype
  • http://github.com/logotype
  • https://logotype.se

Copyright and license

Copyright © 2015 logotype

Author: Victor Norgren

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.