Skip to content

Instantly share code, notes, and snippets.

@ashikawa
Created July 26, 2012 07:51
Show Gist options
  • Save ashikawa/3180821 to your computer and use it in GitHub Desktop.
Save ashikawa/3180821 to your computer and use it in GitHub Desktop.
iOs deveice
function handleMotion(event) {
var orientData = event.accelerationIncludingGravity,
x = orientData.x,
y = orientData.y,
z = orientData.z;
// メインの処理
}
// イベントリスナの登録
window.addEventListener("devicemotion", handleMotion, true);
function deviceOrientHandler(event) {
var head = event.webkitCompassHeading,
alpha = event.alpha,
beta = event.beta,
gamma = event.gamma;
// メインの処理
}
// イベントリスナの登録
window.addEventListener('deviceorientation', deviceOrientHandler, true);
function handleMotion(event) {
// (略)
}
window.addEventListener("devicemotion", handleMotion, true);
// 動作確認用、ダミーデータ入力処理
// 厳密にやるなら setInterval 等
window.triggerMotion = function () {
var dummy = {},
i;
// メイン処理で使う値を任意で合成
for (i = 0; i < 1000; i++) {
// とりあえずランダムな値を放り込む
dummy.accelerationIncludingGravity = {
x: Math.random() * 10,
y: Math.random() * 10,
z: Math.random() * 10
};
// 元の関数を呼び出す
handleMotion(dummy);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment