-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
75 lines (49 loc) · 1.47 KB
/
main.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var box = document.getElementById('marbleBox');
var marble = document.getElementById('marble');
var hole = document.getElementById('hole');
hole.style.top = "80%";
hole.style.left = "80%";
hole.addEventListener('click', () => {
console.log("hole clicked");
})
window.addEventListener("deviceorientation", handleOrientation, true);
const colourBox = (hue) => {
const hslaString = `hsla(${hue}, 100%, 60%, 1)`
console.log(hslaString);
box.style.backgroundColor = hslaString;
}
var i = 0, max = 360, cnt = 10;
const timer = function() {
i += cnt;
if (i===max) {cnt = -10;}
if (i===0) {cnt = 10;}
colourBox(i)
setTimeout(timer, 60);
}
function handleOrientation(event) {
var absolute = event.absolute;
var z = event.alpha;
var x = (event.beta + 90)/1.8;
var y = (event.gamma + 90)/1.8;
if(y===90) y
marble.style.top = x + '%';
marble.style.left = y + '%';
let xupper = 82;
let xlower = 78;
let xtrue = (xupper > x && xlower < x);
let yupper = 82;
let ylower = 78;
let ytrue = (xupper > y && xlower < y);
if(xtrue && ytrue) {
marble.style.display = 'none';
window.navigator.vibrate(300);
timer();
//setInterval(timer, 3);
setTimeout(() => {
marble.style.display = 'inline-block';
}, 1000);
}
// const output = document.getElementById('output');
// output.innerHTML = "beta : " + x + "\n";
// output.innerHTML += "gamma: " + y + "\n";
}