Created
March 31, 2019 17:13
-
-
Save NMZivkovic/ce701a7205b7e8ec128178f6f4e22ba2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateNewPosition(positionx, positiony, direction) | |
{ | |
return { | |
'up' : [positionx, positiony - 10], | |
'down': [positionx, positiony + 10], | |
'left' : [positionx - 10, positiony], | |
'right' : [positionx + 10, positiony], | |
'default': [positionx, positiony] | |
}[direction]; | |
} | |
function predict(contex, positionx, positiony) { | |
const words = recognizer.wordLabels(); | |
recognizer.listen(({scores}) => { | |
scores = Array.from(scores).map((s, i) => ({score: s, word: words[i]})); | |
scores.sort((s1, s2) => s2.score - s1.score); | |
var direction = scores[0].word; | |
var [x1, y1] = calculateNewPosition(positionx, positiony, direction); | |
contex.moveTo(positionx,positiony); | |
contex.lineTo(x1, y1); | |
contex.closePath(); | |
contex.stroke(); | |
positionx = x1; | |
positiony = y1; | |
}, {probabilityThreshold: 0.75}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment