-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
494 lines (427 loc) · 12.9 KB
/
index.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<!--
By Adam Tal
AdmTal@gmail.com
https://github.com/AdmTal/BananaBeat
Inspired by : http://www.youtube.com/watch?v=CZVX7xrld7s
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<meta charset="UTF-8">
<title>Banana Beat</title>
<style type="text/css">
body {
overflow: hidden;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.unselectable {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
/* Introduced in IE 10.
See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/ */
-ms-user-select: none;
user-select: none;
}
a:link {
color: yellow;
}
a:visited {
color: yellow;
}
#color_box {
position: absolute;
left: 50%;
top: 30px;
margin-left: -395px;
width: 730px;
height: 50px;
}
#banana_box {
position: absolute;
background-color: white;
left: 50%;
margin-left: -400px;
width: 800px;
height: 550px;
-moz-border-radius: 15px;
border-radius: 10px;
}
#instructions {
position: absolute;
top: 660px;
width: 95%;
}
#left_peel_1 {
position: absolute;
left: 0px;
top: 0px;
background-image: url(l_1.png);
width: 200px;
height: 500px;
}
#right_peel_1 {
background-image: url(r_1.png);
position: absolute;
left: 200px;
top: 0px;
width: 200px;
height: 500px;
}
#banana_1 {
background-image: url(banana_1.png);
position: absolute;
left: 0px;
top: 0px;
width: 400px;
height: 500px;
}
#left_peel_2 {
position: absolute;
left: 400px;
top: 0px;
background-image: url(l_1.png);
width: 200px;
height: 500px;
}
#right_peel_2 {
background-image: url(r_1.png);
position: absolute;
left: 600px;
top: 0px;
width: 200px;
height: 500px;
}
#banana_2 {
background-image: url(banana_1.png);
position: absolute;
left: 400px;
top: 0px;
width: 400px;
height: 500px;
}
#cb_white {
position: absolute;
background-color: white;
left: 25px;
top: 450px;
width: 100px;
height: 50px;
}
#cb_red {
position: absolute;
background-color: red;
left: 130px;
top: 450px;
width: 100px;
height: 50px;
}
#cb_orange {
position: absolute;
background-color: orange;
left: 235px;
top: 450px;
width: 100px;
height: 50px;
}
#cb_yellow {
position: absolute;
background-color: yellow;
left: 340px;
top: 450px;
width: 100px;
height: 50px;
}
#cb_green {
position: absolute;
background-color: green;
left: 445px;
top: 450px;
width: 100px;
height: 50px;
}
#cb_blue {
position: absolute;
background-color: blue;
left: 550px;
top: 450px;
width: 100px;
height: 50px;
}
#cb_purple {
position: absolute;
background-color: purple;
left: 655px;
top: 450px;
width: 100px;
height: 50px;
}
</style>
<script language="javascript">
// Sound INIT
var T1 = new Audio("T1.wav");
var T2 = new Audio("T2.wav");
var T3 = new Audio("T3.wav");
var T4 = new Audio("T4.wav");
var T5 = new Audio("T5.wav");
var T6 = new Audio("T6.wav");
var tracks = new Array();
tracks["left_peel_1"] = T1;
tracks["right_peel_1"] = T2;
tracks["banana_1"] = T3;
tracks["left_peel_2"] = T4;
tracks["right_peel_2"] = T5;
tracks["banana_2"] = T6;
function set_volume(div, frame) {
if (div[0] == 'b') {
if (frame == 1)
tracks[div].volume = 0;
else
tracks[div].volume = frame * .2;
} else {
switch (frame) {
case 1:
tracks[div].volume = 0;
break;
case 2:
tracks[div].volume = .1;
break;
case 3:
tracks[div].volume = .3;
break;
case 4:
tracks[div].volume = .5;
break;
case 5:
tracks[div].volume = .7;
break;
case 6:
tracks[div].volume = .9;
break;
case 7:
tracks[div].volume = 1;
break;
}
}
}
var track_count = 0;
function end() {
track_count++;
if (track_count == 6) {
play();
track_count = 0;
}
}
T1.setAttribute("onended", "end()");
T2.setAttribute("onended", "end()");
T3.setAttribute("onended", "end()");
T4.setAttribute("onended", "end()");
T5.setAttribute("onended", "end()");
T6.setAttribute("onended", "end()");
// threshold could also be an array, so each div could change its threshold during animation
// this might make the peeling effect nicer
//var drag_threshold = 4;
var drag_threshold = new Array();
drag_threshold["1"] = 4;
drag_threshold["2"] = 5;
drag_threshold["3"] = 5;
drag_threshold["4"] = 6;
drag_threshold["5"] = 7;
drag_threshold["6"] = 7;
drag_threshold["7"] = 8;
var drag_counter = new Array();
var b1_bite = "down";
var b2_bite = "down"
// drag_counter is used with drag_threshold to set the sensitivity of a drag
drag_counter["left_peel_1"] = 0;
drag_counter["right_peel_1"] = 0;
drag_counter["banana_1"] = 0;
drag_counter["left_peel_2"] = 0;
drag_counter["right_peel_2"] = 0;
drag_counter["banana_2"] = 0;
function play() {
T1.play();
T2.play();
T3.play();
T4.play();
T5.play();
T6.play();
}
function startup() {
for (key in tracks) {
tracks[key].volume = 0;
}
play();
}
var was_peeled = false;
function handleMove(x) {
was_peeled = false;
var x_obj = document.getElementById(x);
// For touch devices
x_obj.ontouchmove = function(e) {
var touch = e.touches[0]; // Get the information for finger #1
var moveY = touch.clientY; // Vertical coordinate of the touch point relative to the top edge of the browser
if (moveY < this.lastTouchY) {
peel(x, 'down');
} else if (moveY > this.lastTouchY) {
peel(x, 'up');
}
this.lastTouchY = moveY;
}
// For non-touch devices
x_obj.onmousemove = function(e) {
if (e.movementY < 0) {
peel(x, 'down');
} else if (e.movementY > 0) {
peel(x, 'up');
}
}
x_obj.onmouseup = x_obj.onmouseout = x_obj.ontouchend = function(e) {
x_obj.onmousemove = null;
x_obj.ontouchmove = null;
}
}
function peel(div, dir) {
was_peeled = true;
// get the current frame (image file name is should be animation frame #)
var current_frame = document.getElementById(div).title;
// increment drag_counter[div], and return unless drag_threshold is hit
if (drag_counter[div] != drag_threshold[current_frame]) {
drag_counter[div] = drag_counter[div] + 1;
return;
}
if (dir == "down") {
current_frame = current_frame - 1;
if (current_frame == 0)
current_frame = 1;
} else if (dir == "up") {
current_frame = parseInt(current_frame) + 1;
if (current_frame == 8)
current_frame = 7;
}
if (div[0] == 'l')
document.getElementById(div).style.backgroundImage = "url('l_" + current_frame + ".png')";
else
document.getElementById(div).style.backgroundImage = "url('r_" + current_frame + ".png')";
set_volume(div, parseInt(current_frame));
document.getElementById(div).title = current_frame + '';
drag_counter[div] = 0
}
function bite(div) {
// get the current frame (image file name should be animation frame #)
if (div == 'back')
return;
var current_frame = document.getElementById(div).title;
if (div == "banana_1") {
if (b1_bite == "down") {
current_frame = parseInt(current_frame) + 1;
if (current_frame == 6) {
current_frame = 5;
b1_bite = "up";
}
} else {
current_frame = parseInt(current_frame) - 1;
if (current_frame == 0) {
current_frame = 1;
b1_bite = "down";
}
}
} else {
if (b2_bite == "down") {
current_frame = parseInt(current_frame) + 1;
if (current_frame == 6) {
current_frame = 5;
b2_bite = "up";
}
} else {
current_frame = parseInt(current_frame) - 1;
if (current_frame == 0) {
current_frame = 1;
b2_bite = "down";
}
}
}
document.getElementById(div).style.backgroundImage = "url('banana_" + current_frame + ".png')";
set_volume(div, parseInt(current_frame));
document.getElementById(div).title = current_frame + '';
}
function change_color(color) {
document.getElementById("banana_box").style.backgroundColor = color;
document.getElementById("banana_box") = document.getElementById("banana_box");
}
</script>
<script type="text/javascript">
function blockMove() {
event.preventDefault();
}
</script>
</head>
<body bgcolor="black">
<center>
<p><b>
<font color="yellow" vlink="yellow" face="modern" size="16"><a href="http://www.youtube.com/watch?v=CZVX7xrld7s">Banana Beat</a></font>
</b></p>
<div id="overlay" style="position: fixed; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; z-index: 1000; background: rgba(0, 0, 0, 0.5);">
<button id="startBtn" style="position: absolute; top: 20%; left: 50%; transform: translate(-50%, -50%);">Start the music!</button>
<p style="position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%);">
Instructions :<br />
Turn speakers up!<br />
Click + drag to peel<br />
Double click to bite
</p>
</div>
<div id="banana_box" class="unselectable" style="border-style:solid; border-color:black;">
<div id="banana_1" title="1"></div>
<div id="left_peel_1" ontouchstart="handleMove('left_peel_1')" onmousedown="handleMove('left_peel_1')" title="1" ondblclick="bite('banana_1')"></div>
<div id="right_peel_1" ontouchstart="handleMove('right_peel_1')" onmousedown="handleMove('right_peel_1')" title="1" ondblclick="bite('banana_1')"></div>
<div id="banana_2" title="1"></div>
<div id="left_peel_2" ontouchstart="handleMove('left_peel_2')" onmousedown="handleMove('left_peel_2')" title="1" ondblclick="bite('banana_2')"></div>
<div id="right_peel_2" ontouchstart="handleMove('right_peel_2')" onmousedown="handleMove('right_peel_2')" title="1" ondblclick="bite('banana_2')"></div>
<div id="color_box">
<div id="cb_white" onClick="change_color('white')" style="border-style:solid;"></div>
<div id="cb_red" onClick="change_color('red')" style="border-style:solid;"></div>
<div id="cb_orange" onClick="change_color('orange')" style="border-style:solid;"></div>
<div id="cb_yellow" onClick="change_color('yellow')" style="border-style:solid;"></div>
<div id="cb_green" onClick="change_color('green')" style="border-style:solid;"></div>
<div id="cb_blue" onClick="change_color('blue')" style="border-style:solid;"></div>
<div id="cb_purple" onClick="change_color('purple')" style="border-style:solid;"></div>
</div>
</div>
<div id="instructions" aligh="center">
<center>
<b>
<font color=white>
Instructions :<br />
Turn speakers up!<br />
Click + drag to peel<br />
Double click to bite
</font>
</b>
</center>
</div>
<script>
document.getElementById('startBtn').addEventListener('click', function() {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
alert('Due to mobile limitations, this experience only works on Desktop.');
return;
}
var audio = document.getElementById('myAudio');
startup();
document.getElementById('overlay').style.display = 'none';
});
document.querySelectorAll('#left_peel_1, #right_peel_1, #left_peel_2, #right_peel_2').forEach(function(element) {
element.addEventListener('touchend', function() {
if (was_peeled) return;
if (element.id === 'left_peel_1' || element.id === 'right_peel_1') {
bite('banana_1');
} else if (element.id === 'left_peel_2' || element.id === 'right_peel_2') {
bite('banana_2');
}
});
});
</script>
</body>
</html>