forked from salcosta/party_mode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnachoMode.js
104 lines (86 loc) · 2.75 KB
/
nachoMode.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
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
var container = document.createElement("div");
var sombrero = document.createElement("img");
var iframe = document.createElement("iframe");
var canvas = document.createElement("canvas");
var nachos = [];
canvas.style.position ="fixed";
canvas.style.top = 0;
canvas.style.left=0;
canvas.style.width="100%";
canvas.style.height="100%";
canvas.style.opacity="0.5";
document.body.appendChild(canvas);
sombrero.src = "http://i.imgur.com/en3T7Wk.png";
sombrero.style.display = "block";
sombrero.style.margin = "0 auto";
container.appendChild(sombrero);
iframe.src="https://www.youtube.com/embed/vX2J6mceWic?rel=0&autoplay=1";
iframe.style.height = "100px";
iframe.style.width = "140px";
iframe.style.display = "block";
iframe.style.margin = "0 auto";
container.appendChild(iframe);
container.style.bottom = "-175px";
container.style.position = "fixed";
container.style.width = "80%";
container.style.margin = "0 0 0 -40%";
container.style.left = "50%";
container["z-index"] = -1;
document.body.appendChild(container);
window.requestAnimFrame = (function(){
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ){
window.setTimeout(callback, 10000);
};
})();
moveUp();
createNacho();
requestAnimFrame(function() {
animateNachos(canvas.getContext("2d"), canvas, nachos);
});
function createNacho(){
nachos.push({
height: 0,
x: (Math.random() * canvas.width),
fallSpeed : 1,
c: "yellow"
});
}
function animateNachos(context, canvas, nachos){
context.clearRect(0, 0, canvas.width, canvas.height);
updateNachos(nachos, canvas);
drawNachos(nachos, context);
requestAnimFrame(function() {
animateNachos(context,canvas, nachos);
});
}
function drawNacho(x, height, ctx){
ctx.beginPath();
ctx.moveTo(x,height+30);
ctx.lineTo(x+10,height+10);
ctx.lineTo(x+30,height+30);
ctx.closePath();
ctx.fillStyle = "#FFCC00";
ctx.fill();
}
function drawNachos(nachos, context){
nachos.forEach(function(nacho){
drawNacho(nacho.x, nacho.height, context);
});
}
function updateNachos(nachos, canvas){
for (var i=0; i<nachos.length; i++){
var nacho=nachos[i];
if ((nacho.height === 40) && (nachos.length < 7)){
createNacho();
}
if (nacho.height === canvas.height){
nacho.height = 0;
nacho.x = (Math.random() * canvas.width);
}
nacho.height += nacho.fallSpeed;
}
}
function moveUp() {
container.style.bottom = (parseInt(container.style.bottom.slice(0, -2)) + 3).toString() + "px";
setTimeout(moveUp, 500);
}