<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="user-scalable=no, width=device-width" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
<script type="text/javascript" src = "http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src = "http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
window.addEventListener("devicemotion",onDeviceMotion,false);
});
function onDeviceMotion(event){
var ctx = document.getElementById("c").getContext("2d");
var accel = event.accelerationIncludingGravity;
$("#sliderX").val(Math.round(accel.x)).slider("refresh");
$("#sliderY").val(Math.round(accel.y)).slider("refresh");
$("#sliderZ").val(Math.round(accel.z)).slider("refresh");
var angle = Math.atan2(accel.y,accel.x)
ctx.clearRect(0,0,100,100);
ctx.beginPath();
ctx.arc(50,50,5,0,2*Math.PI,false);
ctx.moveTo(50,50);
ctx.lineTo(50-50*Math.cos(angle),50+50*Math.sin(angle));
ctx.stroke();
}
</script>
</head>
<body>
<div data-role="page" id = "intropage">
<div data-role="header">
<h1>Accelerometer</h1>
</div>
<div data-role="content">
<label for="sliderX">X Acceleration (Roll)</label>
<input type="range" name="sliderX" id="sliderX" value="0" min="-10" max="10" data-theme="a" />
<label for="sliderY">Y Acceleration (Pitch)</label>
<input type="range" name="sliderY" id="sliderY" value="0" min="-10" max="10" data-theme="b" />
<label for="sliderZ">Z Acceleration (<strike>Yaw</strike> Face up/down)</label>
<input type="range" name="sliderZ" id="sliderZ" value="0" min="-10" max="10" data-theme="c" />
</div>
<p style = "text-align:center">SKY direction: follow this line:</p>
<div style = "text-align:center;margin-top:10px;">
<canvas id="c" width="100" height="100"></canvas>
</div>
</div>
</body>
</html>
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |