Mouse Position Prediction Library – mpredict.js

Category: Javascript | June 10, 2016
Author: cudbg
Views Total: 2,090
Official Page: Go to website
Last Update: June 10, 2016
License: MIT

Preview:

Mouse Position Prediction Library – mpredict.js

Description:

mpredict.js is a no-dependency JavaScript library used to predict the mouse position.

See also:

How to use it:

Make sure the mpredict.js and mpredict-templates.json files are placed at the same folder. Then include the mpredict.js script on your webpage as follow:

<script src="mpredict.js"></script>

Start predicting mouse position:

mPredict.start();

Possible options with default values:

mPredict.start({

  // The time interval(by milliseconds) of sampling the mouse trace
  sampleInterval: 10,

  // he time threshold of pausing; when the time between two consecutive mouse events is larger than this threshold, the second mouse event will be regarded as the beginning of a new trace
  pauseThreshold: 50,

  // The number of nearest neighbors in the KNN algorithm
  K: 5,

  // The path to the JSON file of templates used for the KNN algorithm
  pathToTemplates: './mpredict-templates.json',

  // The selector of target element to record mouse trace from
  targetElement: 'document'
  
});

API.

// Get the current mouse trace recorded and sampled by MPredict.js on the target DOM element
mPredict.getCurrentTrace()

// Sample a mouse trace for prediction
// trace : Array: [[x0, y0, t0], ..., [xn, yn, tn]], xi and yi are mouse positions(in pixels), ti is the timestamp
mPredict.sampleTrace(trace)

// Predict the mouse position for the given trace after deltaTime
// trace : sampled mouse trace
// deltaTime : integer(in milliseconds), deltaTime <= 0 means predicting the endpoint for the given trace
mPredict.predictPosition(trace, deltaTime)

You Might Be Interested In:


Leave a Reply