summaryrefslogtreecommitdiffstats
path: root/examples/declarative/workerscript/workerscript.js
blob: f76471f9201cb43d2f75d01662fa907473f9668a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var lastx = 0;
var lasty = 0;

WorkerScript.onMessage = function(message) {
    var ydiff = message.y - lasty;
    var xdiff = message.x - lastx;

    var total = Math.sqrt(ydiff * ydiff + xdiff * xdiff);

    lastx = message.x;
    lasty = message.y;

    WorkerScript.sendMessage( {xmove: xdiff, ymove: ydiff, move: total} );
}