-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (36 loc) · 845 Bytes
/
app.js
File metadata and controls
46 lines (36 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function () {
"use strict";
var threshold, audio;
function getThreshold () {
return threshold;
}
function setThreshold (t) {
threshold = t;
}
function scream (start) {
if (start) {
audio.loop = true;
audio.play();
} else {
audio.loop = false;
}
}
function init (callback, getThreshold) {
var isFalling = false, input;
audio = document.getElementById('scream');
input = document.getElementById('threshold');
input.addEventListener('change', function () {
setThreshold(input.value);
}, false);
setThreshold(input.value);
window.addEventListener('devicemotion', function (e) {
var a = e.accelerationIncludingGravity;
a = Math.sqrt(a.x * a.x + a.y * a.y + a.z * a.z);
if ((a < getThreshold()) !== isFalling) {
isFalling = !isFalling;
callback(isFalling);
}
}, false);
}
init(scream, getThreshold);
})();