Skip to content

Instantly share code, notes, and snippets.

@vinc
Created March 1, 2014 12:31
Show Gist options
  • Save vinc/9289131 to your computer and use it in GitHub Desktop.
Save vinc/9289131 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Accelerocolor</title>
<script type="text/javascript">
window.onload = function() {
var rgb = [255, 255, 255];
var orientation = [0.0, 0.0, 0.0];
var update = function(i, x) {
var c = 1;
if (x > orientation[i] + c) {
rgb[i] = Math.min(rgb[i] + 1, 255);
} else if (x < orientation[i] - c) {
rgb[i] = Math.max(rgb[i] - 1, 0);
}
orientation[i] = x;
}
window.addEventListener('deviceorientation', function(event) {
update(0, event.alpha);
update(1, event.beta);
update(2, event.gamma);
document.body.style.background = 'rgb(' + rgb.join(', ') + ')';
});
};
</script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment