-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhacky-bird.html
More file actions
194 lines (143 loc) · 4.39 KB
/
hacky-bird.html
File metadata and controls
194 lines (143 loc) · 4.39 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
}
#itis {
width: 640px;
height: 480px;
position: relative;
}
h1 {
font-size: 3em;
position: absolute;
transition: all .1s;
transform: scaleX(-1);
animation: spasm .4s ease forwards infinite;
}
video {
opacity: .2;
position: absolute;
top: 0;
left: 0;
}
@keyframes spasm {
0%,
100% {
transform: scale(1) scaleX(-1);
}
50% {
transform: scale(1.2) scaleX(-1);
}
}
@keyframes scroll {
0% {
right: -100px;
}
100% {
right: 740px;
}
}
#pipes {
position: relative;
width: 640px;
height: 480px;
margin: 0; padding: 0;
overflow: hidden;
}
#pipes li {
display: block;
position: absolute;
height: 100px;
width: 100px;
background-size: cover;
animation: scroll 10s linear infinite forwards;
}
/* posiiton top pipe */
#pipes li:nth-child(1),
#pipes li:nth-child(2n+1) {
top: 0;
background-image: url(pipe2.png);
background-position: center bottom;
}
#pipes li:nth-child(2n) {
bottom: 0;
background-image: url(pipe1.png);
background-position: center top;
}
#pipes li:nth-child(3) {
height: 200px;
transform: translateX(400px);
}
#pipes li:nth-child(2) {
height: 200px;
}
#pipes li:nth-child(4) {
transform: translateX(400px);
}
</style>
</head>
<body>
<div id="itis">
<h1 id="leftEye">🐦</h1>
<h1 id="rightEye">🐦</h1>
<h1 id="nose">🐦</h1>
<ul id="pipes">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<script src="https://unpkg.com/@tensorflow/tfjs"></script>
<script src="https://unpkg.com/@tensorflow-models/posenet">
</script>
<script type="module">
import { PoseStream } from './poses.js';
function intersectRect(rectA, rectB) {
return !(
rectB.left >= rectA.right ||
rectB.right <= rectA.left ||
rectB.top >= rectA.bottom ||
rectB.bottom <= rectA.top
);
}
let started = false;
// Video stream - in progress
const stream = new PoseStream({ delay: 10 });
stream.start()
stream.addEventListener('pose', (event) => {
let { x, y } = event.data.keypoints[0].position
nose.style.left = ((x / stream.video.width) * 100) + '%'
nose.style.top = ((y / stream.video.height) * 60) + '%'
leftEye.style.left = ((event.data.keypoints[1].position.x / stream.video.width) * 100) + '%'
leftEye.style.top = ((event.data.keypoints[1].position.y / stream.video.height) * 60) + '%'
rightEye.style.left = ((event.data.keypoints[2].position.x / stream.video.width) * 100) + '%'
rightEye.style.top = ((event.data.keypoints[2].position.y / stream.video.height) * 60) + '%'
started = true;
})
let lost = false;
setInterval(() => {
if(started) {
const bird = nose.getBoundingClientRect()
for(const el of document.querySelectorAll('#pipes li')) {
const pipe = el.getBoundingClientRect()
if(intersectRect(bird, pipe)) {
if(lost === false) {
alert("LOST")
}
lost = true;
}
}
}
}, 200)
</script>
</body>
</html>