Coder Social home page Coder Social logo

vmikhav / jager Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 2.0 23 KB

Javascript touch gesture recognition library

License: MIT License

JavaScript 100.00%
gesture-recognition gesture pigtail javascript-library gesture-recognizer javascript-plugin symbols recognition touch-gesture

jager's Introduction

Description

Jager is an library for touch gesture / symbols recognition.

Features

  • Simple API
  • Fast recognition (around 0.2 ms)
  • Recognition on-the-fly
  • No outside dependencies, just pure JavaScript

Usage

Library is used in next projects:

Documentation

Contents

Quick Start

  • Clone the repo: git clone https://github.com/vmikhav/jager.git

In the browser:

<script src="/path/to/jager.js"></script>
<script>
    var jager = new Jager();
</script>

Examples

const jager = new Jager();
jager.addPoint({x, y});
let symbols = jager.recognise();

Also you can see this demo page.

Options

path

Array of points (x, y) for recognition

symbols

Object with symbols enumeration

if (jager.recognise() === jager.symbols['pigtail']) { }

symbolsRules

Array of symbol patterns. Pattern contain the following fields:

  • symbol: {name, index} Symbol info.
  • sections: Array Rules for path sections. Each rule contain the following elements:
    • x -1|0|1 Section orientation in X line. Should be 0 if y is not 0.
    • y -1|0|1 Section orientation in Y line. Should be 0 if x is not 0.
    • skip bool Optional If true, this section can be skipped in mismatch case.
  • quarters: function (sX, sY, eX, eY) Callback function to check start and end point positions. Each param is in integer range [0, 3] (top-left corner is (0, 0), bottom-right is (3, 3)).
{
  symbol: this.symbols['circle'],
  sections: [{x: -1, y: 0, skip: true}, {x: 0, y: 1}, {x: 1, y: 0}, {x: 0, y: -1}, {x: -1, y: 0}],
  quarters: function (sX, sY, eX, eY) {
    return sY === 0 && eY === 0 && Math.abs(sX - eX) <= 1 && sX <= 2;
  }
}

Methods

reset()

Reset current path.

point(evt)

Extract point object from the event data.

  • evt: Event parameter.

pushPoint(point)

Add point to current path without changes.

  • point: Point object, contains x and y.

addPoint(point[, distanceFilter[, smoothFactor]])

Add point to current path with smoothing.

  • point: Point object, contains x and y.
  • distanceFilter: Ignore point if squared distance to previous point is less than distanceFilter.
  • smoothFactor: How smooth will be current path. Decimal in [0, 1).

recognise([debug])

Recognizes the painted gesture.

  • debug: Bool optional If true jager logging the symbol info.

drawPatch(ctx)

Draw current path in given ctx.

  • ctx: Context Canvas context.

License

This software is licensed under the MIT © vmikhav

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.