Last active
August 29, 2015 14:01
-
-
Save tkojitu/2369ad5b427ca2ef3bbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="devmot.js"></script> | |
</head> | |
<body> | |
<table border=1> | |
<tr><td>x</td><td id="x">0</td></tr> | |
<tr><td>y</td><td id="y">0</td></tr> | |
<tr><td>z</td><td id="z">0</td></tr> | |
<tr><td>v</td><td id="v">0</td></tr> | |
</table> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onLoad() { | |
window.addEventListener("devicemotion", onDeviceMotion, false); | |
} | |
function onDeviceMotion(event) { | |
var acc = event.accelerationIncludingGravity; | |
var x = acc.x; | |
var y = acc.y; | |
var z = acc.z; | |
var v = Math.sqrt(x * x + y * y + z * z); | |
showValue("x", x); | |
showValue("y", y); | |
showValue("z", z); | |
showValue("v", v); | |
} | |
function showValue(id, value) { | |
var elm = document.getElementById(id); | |
elm.innerHTML = "" + value; | |
} | |
window.addEventListener("load", onLoad, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment