Created
March 1, 2014 12:31
-
-
Save vinc/9289131 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
<!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