-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.html
120 lines (110 loc) · 2.88 KB
/
level.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!doctype html>
<html>
<head>
<title>Level</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="author" content="Justin McConnell">
<meta name="url" content="https://github.com/JustinMcConnell">
<style>
body {
font-family: sans-serif;
}
#level {
position: relative;
width: 80%;
height: 70px;
margin: 0 auto;
}
#glass {
background-color: lightgreen;
border-radius: 20px;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 5;
}
#right_bar,
#left_bar {
position: absolute;
z-index: 15;
background-color: #000000;
height: 100%;
width: 4px;
}
#right_bar {
right: 43%;
}
#left_bar {
left: 43%;
}
#bubble {
position: absolute;
width: 10%;
height: 80%;
top: 10%;
left: 45%;
background-color: #fff;
border-radius: 25px;
z-index: 10;
}
#output {
position: absolute;
left: 0;
bottom: -25px;
width: 100%;
text-align: center;
font-size: larger;
}
</style>
</head>
<body>
<div id="level">
<div id="glass"></div>
<div id="right_bar"></div>
<div id="left_bar"></div>
<div id="bubble"></div>
<div id="output"></div>
</div>
<script>
(function() {
function get_orientation() {
if (typeof window.orientation != "undefined") {
return window.orientation == 0 ? "portrait" : "landscape";
} else if (typeof screen.mozOrientation != "undefined") {
return screen.mozOrientation == "portrait-primary" ? "portrait" : "landscape";
}
return "portrait";
}
function do_orientation(event) {
var orientation = get_orientation();
var y = orientation == "portrait" ?
event.gamma.toFixed(1) :
event.beta.toFixed(1);
var bubble_left = ((Math.tan(-y / 45) * level_width / 2) +
(level_width / 2) -
(bubble_width / 2)).toFixed(0);
if (bubble_left < 0) {
bubble_left = 0;
} else if (bubble_left > level_width - bubble_width) {
bubble_left = level_width - bubble_width;
}
bubble.style.left = bubble_left + "px";
output.innerHTML = Math.abs(y);
}
var output = document.getElementById("output");
var bubble = document.getElementById("bubble");
var bubble_width = parseInt(window.getComputedStyle(bubble, null).getPropertyValue("width"), 10);
var level = document.getElementById("level");
var level_width = parseInt(window.getComputedStyle(level, null).getPropertyValue("width"), 10);
level.style.height = (level_width * .07) + "px";
if (typeof window.DeviceOrientationEvent === "function") {
window.addEventListener("deviceorientation", do_orientation, true);
} else {
output.innerHTML = "Ack! Yer computer doesnae dae device orientation.";
}
}());
</script>
</body>
</html>