Created
July 26, 2012 07:51
-
-
Save ashikawa/3180821 to your computer and use it in GitHub Desktop.
iOs deveice
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
function handleMotion(event) { | |
var orientData = event.accelerationIncludingGravity, | |
x = orientData.x, | |
y = orientData.y, | |
z = orientData.z; | |
// メインの処理 | |
} | |
// イベントリスナの登録 | |
window.addEventListener("devicemotion", handleMotion, true); |
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
function deviceOrientHandler(event) { | |
var head = event.webkitCompassHeading, | |
alpha = event.alpha, | |
beta = event.beta, | |
gamma = event.gamma; | |
// メインの処理 | |
} | |
// イベントリスナの登録 | |
window.addEventListener('deviceorientation', deviceOrientHandler, true); |
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
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