Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created March 31, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/ce701a7205b7e8ec128178f6f4e22ba2 to your computer and use it in GitHub Desktop.
Save NMZivkovic/ce701a7205b7e8ec128178f6f4e22ba2 to your computer and use it in GitHub Desktop.
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