Vue-path-recognizer
Path Recognizing component for Vue.
Installation
Basic usage
Import the PathRecongizer component. PathRecognizer is a container, it requires a child element to capture mouse moves. PathRecognizer does not draw the moves, for a full drawing example, check the example/ folder of this repo.
Add some path model to the recognizer.
Each path is defined by a direction-sequence and an associated data object.
Wrap your sliding template range
For example, here the model for the letter E :
Set the models and the onGesture prop on the PathRecognizer component :
Note that onGesture({datas}) is always invoked at the end of the drawing. If no gesture is recognized, this parametter is null.
Custom filter
While adding a model, you can specify a custom filter (third parametter of PathRecognizerModel). The filter callback method, if specified, will let you a last chance to modify / analyze the datas to determine a new score.
For example, the letter D & P have a similar draw-direction-path, however you can discriminate each one by detecting the position of the last point (up -> it's a P, down -> it's a D). The PathInfos struct transmited to the filter function will help you to determine the new score.
For a full example, please consult the example folder of this repo.
API
PathRecognizer props
name | type | default | description |
---|---|---|---|
sliceCount | Number | 8 | Resolution of the direction wheel |
deltaMove | Number | 8 | Mouse move threshold (pixels) |
costMax | Number | 32 | Max cost limit to detect a gesture |
models | [PathRecognizerModel([Number], Any)] | [] | Models to recognize |
onStartDraw | Function() | function | Invoked when the user mouse down the zone |
onMovePath | Function([{x:Number, y:Number}]) | function | Invoked when the user move his mouse during a record session |
onStopDraw | Function() | function | Invoked when the user mouse up the zone |
onGesture | Function(datas:Any) | function | Invoked with the datas of the model recognized or null if no gesture is recognized |
Free path
In this sample project I've used the Graffiti alphabet for the didactic aspect. However, react-path-recognizer is a generic algorithm, you can add any free path to control an interface / game :
References & Original Authors
Didier Brun