Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ifrost/moses
JavaScript mouse/touch gesture recognition library
https://github.com/ifrost/moses
Last synced: 4 months ago
JSON representation
JavaScript mouse/touch gesture recognition library
- Host: GitHub
- URL: https://github.com/ifrost/moses
- Owner: ifrost
- Created: 2016-02-13T14:21:06.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-26T09:09:16.000Z (7 months ago)
- Last Synced: 2024-10-02T02:43:27.824Z (4 months ago)
- Language: JavaScript
- Homepage: http://ifrost.github.io/moses/html/demo/
- Size: 98.6 KB
- Stars: 15
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-actionscript-sorted - moses - Mouse Gesture Recognition in ActionScript 3 (Unsorted / Other API)
README
# Moses
JavaScript library for mouse/touch gesture recognition.
It's a JS version of https://github.com/ifrost/moses-flash.
# Demo
http://ifrost.github.io/moses/html/demo/
# How it works?
A `Sampler` is responsible for capturing user events and dispatching sampling events with a list of sampled points.
A `Recogniser` listens to sampling events. When a gesture is sampled recogniser processes the data. It checks all registered `Patterns` and runs the pattern's `Algorithm` passing sampled data. Each `Pattern` contains data that is used by algorithm to compare with the sampled points. `Algorithm` returns a `Match` object with 0-1 value showing how well recognition of the pattern went.
Samplers (`js/sampler`):
*`DistanceSampler` based on the distance between points
*`TimeSampler` based on time delayRecognisers (`js/reconigser`):
* `DefaultRecogniser`Algorithms (`js/algorithm`):
* `DefaultMosesAlgorithm` based on simplified directions (similar to http://www.bytearray.org/?p=91)
* `ShiftedPointsMosesAlgorithm` variaton of `DefaultMosesAlgorithm` that shifts the points before recognition so closed patterns can be recognises from any starting point
* `ReversedMosesAlgorithm` variation of `DefaultMosesAlgorithm` that additionally compares the pattern with data points in reversed order
* `PolygonalLineAlgorithm` recognising polygonal lines
* `StraightLineAlgorithm` recognising if the gesture was a simple, straight line
* `PatternCollectionAlgorithm` algorithm used by `PatternCollection`Some predefined patterns are available: `moses.model.MosesPatterns.create()`.
# Example
``` javascript
// create collection of predefined patterns
var mosesPatterns = moses.model.MosesPatterns.create();
// choose patterns from the collection
var patterns = [mosesPatterns.V, mosesPatterns.CIRCLE, mosesPatterns.DASH, mosesPatterns.SQUARE, mosesPatterns.SEVEN, mosesPatterns.Z];
// create a sampler
var div = document.getElementById("sampler");
var sampler = moses.sampler.DistanceSampler.create(div, 5);// create a recogniser
var recogniser = moses.recogniser.DefaultRecogniser.create();// register selecte patterns
patterns.forEach(function(pattern) {
recogniser.register(pattern);
});// display the result
recogniser.on('recognised', function(data) {
var text;
console.log('Best match:', data.bestMatch);
if (data.bestMatch.recognised) {
text = 'Recognised: ' + data.bestMatch.pattern.name + ' (' + Math.floor(data.bestMatch.value * 100) + '%)';
console.log(text);
}
else {
text = 'Not recognised. Was it ' + data.bestMatch.pattern.name + '? (' + Math.floor(data.bestMatch.value * 100) + '%)';
console.log(text);
}
});// assign sampler to the recogniser
recogniser.sampler = sampler;// activate the sampler
sampler.activate();```