-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburnsbox.html
139 lines (124 loc) · 3.92 KB
/
burnsbox.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
<!doctype html>
<html lang=en>
<head>
<title>BurnsBox</title>
<meta charset=utf-8>
<style>
body {
font-family: Avenir, sans-serif;
background-color: #000; margin: 0;
}
#burnsbox-control {
background: #ccc;
padding: 1rem;
}
#canvas { min-height: 10vh; }
#burnsbox-control input {
vertical-align: middle;
margin: 0 1rem;
}
#startbutton {
display: none;
}
:-webkit-full-screen {
position: fixed;
width: 100%;
top: 0;
min-height: 100vh;
}
</style>
</head>
<body>
<div id="burnsbox-control">
<label for="imgfile">Image Files</label>
<input type="file" id="imgfile" multiple accept="image/*">
<label for="musicfile">Background Music</label>
<input type="file" id="musicfile" accept="audio/*">
<label for="bgcolor">Background color</label>
<input type="color" value="#000000" id="bgcolor" oninput="changeBG(bgcolor.value)">
<button id="startbutton">START</button>
</div>
<div id="canvas"></div>
<script>
var imgArray = [];
var newimg = document.createElement("img");
var musicplayer = document.createElement("audio");
var startbutton = document.getElementById("startbutton");
var controlpanel = document.getElementById("burnsbox-control");
var canvas = document.getElementById("canvas");
var bgcolor = document.getElementById("bgcolor");
var end = false;
newimg.id = "newimg";
function addMedia(e) {
e.stopPropagation();
e.preventDefault();
var files = e.target.files;
if (files[0].type == "image/jpg" || files[0].type == "image/jpeg" || files[0].type == "image/png" || files[0].type == "image/gif" ) {
// must be images
for (var i = 0, f; f = files[i]; ++i) {
imgArray[i] = URL.createObjectURL(files[i]);
}
startbutton.style.display = "inline-block";
}
if (files[0].type == "audio/mp3") {
var music = URL.createObjectURL(e.target.files[0]);
musicplayer.src = music;
musicplayer.id = "bgsound";
document.body.appendChild(musicplayer);
musicplayer.autoplay = "true";
musicplayer.loop = "true";
}
}
function launchFullScreen(element) {
if (element.requestFullscreen)
{ element.requestFullscreen(); }
else if (element.mozRequestFullScreen)
{ element.mozRequestFullScreen(); }
else if (element.webkitRequestFullscreen)
{ element.webkitRequestFullscreen(); }
else if (element.msRequestFullscreen)
{ element.msRequestFullscreen(); }
document.styleSheets[0].addRule(':-webkit-full-screen', 'background: ' + bgcolor.value);
drift(0);
}
function changeBG(colorValue) {
canvas.style.backgroundColor = colorValue;
}
document.getElementById("imgfile").onchange = addMedia;
document.getElementById("musicfile").onchange = addMedia;
document.getElementById("startbutton").onclick = function(){ launchFullScreen(canvas) };
function drift(index) {
canvas.style.minHeight = "100vh";
document.addEventListener('webkitfullscreenchange', exitHandler, false);
newimg.src = imgArray[index];
canvas.appendChild(newimg);
newimg.style.width = "40%";
var startPercentageX = Math.floor(Math.random() * ((300 - (-100)) + 1) + (-100));
if (startPercentageX > 200) {
var endPercentageX = Math.floor(Math.random() * ((200 - (-100)) + 1) + (-200));
} else {
endPercentageX = Math.floor(Math.random() * ((300 - 100) + 1) + 100);
}
var player = newimg.animate([
{transform: 'translate(' + startPercentageX + '%, -100%)', opacity: '0'},
{transform: 'translate('+(endPercentageX - startPercentageX) + ', 50%)', opacity: '1'},
{transform: 'translate(' + endPercentageX + '%, 200%)', opacity: '0' }
], { duration: 25000, easing: "linear" });
function exitHandler(){
if (document.webkitIsFullScreen == false) {
player.cancel();
var bgsound = document.getElementById("bgsound");
if (bgsound !== null) { bgsound.pause(); }
canvas.remove();
end = true;
return;
}
}
player.onfinish = function(e) {
newimg.src = "";
if (index < imgArray.length - 1) { drift(index + 1); } else { drift(0); }
}
}
</script>
</body>
</html>