Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Created December 12, 2011 04:17
Show Gist options
  • Save ympbyc/1464825 to your computer and use it in GitHub Desktop.
Save ympbyc/1464825 to your computer and use it in GitHub Desktop.
寝返ったーiOS4.2+版
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);
@ympbyc
Copy link
Author

ympbyc commented Dec 12, 2011

ブログ用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment