Created
December 12, 2011 04:17
-
-
Save ympbyc/1464825 to your computer and use it in GitHub Desktop.
寝返ったーiOS4.2+版
This file contains 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
var prevpos = 0; //一つ前の状態を管理 | |
var negaeri = function(e){ | |
var x; | |
if (Math.abs((x = Math.floor(e.accelerationIncludingGravity.x)) - prevpos) > 5) | |
{ | |
if ((prevpos < 0 && x < 0) || (prevpos > 0 && x > 0)) return; | |
var stat = (x > -2 && x < 2) ? "上を向いたようです" : (x < prevpos) ? "右に寝返りをうったようです" : "左に寝返りをうったようです"; | |
prevpos = x; | |
var d = new Date(); | |
var tweet = d.getHours() + "時" + d.getMinutes() + "分" + d.getSeconds() + "秒に" + stat + " #negaeri"; | |
log(stat); | |
TwitterAPI.statuses.update(tweet); | |
} | |
} | |
window.addEventListener( | |
"devicemotion", | |
function(e){ | |
negaeri(e); | |
}, | |
true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ブログ用