[OpenLayers-Commits] r11680 - sandbox/cmoullet/openlayers/examples
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Mar 8 16:39:24 EST 2011
Author: cmoullet
Date: 2011-03-08 13:39:23 -0800 (Tue, 08 Mar 2011)
New Revision: 11680
Added:
sandbox/cmoullet/openlayers/examples/dpx.html
Log:
Add tschaub examples/dpx.html with standard deviation and mean
Added: sandbox/cmoullet/openlayers/examples/dpx.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/dpx.html (rev 0)
+++ sandbox/cmoullet/openlayers/examples/dpx.html 2011-03-08 21:39:23 UTC (rev 11680)
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>dpx</title>
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0;">
+ <style type="text/css">
+ html, body {
+ height: 100%;
+ margin: 0;
+ }
+
+ #target {
+ width: 100%;
+ height: 100%;
+ background: #ccc;
+ font-size: 3em;
+ text-align: center;
+ }
+ </style>
+</head>
+<body>
+<div id="target">tap twice</div>
+
+<script type="text/javascript">
+ var counter = 0;
+ var dist = 0;
+ var distArray = [];
+ var x, y;
+ var target = document.getElementById("target");
+ // Statistic function for average, variance and standard deviation
+ var average = function(a) {
+ var r = {mean: 0, variance: 0, deviation: 0}, t = a.length;
+ for (var m, s = 0, l = t; l--; s += a[l]) {
+ }
+ for (m = r.mean = s / t,l = t,s = 0; l--; s += Math.pow(a[l] - m, 2)) {
+ }
+ return r.deviation = Math.sqrt(r.variance = s / t),r;
+ };
+ function down(evt) {
+ var newX = evt.touches && evt.touches[0].clientX || evt.clientX;
+ var newY = evt.touches && evt.touches[0].clientY || evt.clientY;
+ if (typeof x !== "number") {
+ x = newX;
+ y = newY;
+ } else {
+ ++counter;
+ dist = Math.sqrt(
+ Math.pow(x - newX, 2) +
+ Math.pow(y - newY, 2)
+ );
+ distArray.push(dist);
+ target.innerHTML = "pair " + counter + " - dist : " + ( dist | 0) +
+ " - avg: " + Math.round(average(distArray).mean * 10) / 10 +
+ " - std: " + Math.round(average(distArray).deviation * 10) / 10;
+ x = null;
+ y = null;
+ }
+ evt.preventDefault();
+ }
+ target.addEventListener("touchstart", down, false);
+ target.addEventListener("mousedown", down, false);
+</script>
+</body>
+</html>
More information about the Commits
mailing list