summaryrefslogtreecommitdiffstats
path: root/examples/declarative/workerscript/workerscript.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/workerscript/workerscript.js')
-rw-r--r--examples/declarative/workerscript/workerscript.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/declarative/workerscript/workerscript.js b/examples/declarative/workerscript/workerscript.js
new file mode 100644
index 0000000..f76471f
--- /dev/null
+++ b/examples/declarative/workerscript/workerscript.js
@@ -0,0 +1,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} );
+}
+