Repository navigation
Expand file tree
/
Copy pathsnake.js
More file actions
156 lines (114 loc) · 3.47 KB
/
Copy pathsnake.js
File metadata and controls
156 lines (114 loc) · 3.47 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
function snake(time,callback){
//effect last for 10 seconds
setTimeout(function(){
container.classList.toggle("hidden");
callback();
}, time);
//get the dom element in which we want to draw
var container = document.getElementById("snake");
container.classList.toggle("hidden");
HTMLElement.prototype.appendFirst=function(childNode){
if(this.firstChild)this.insertBefore(childNode,this.firstChild);
else this.appendChild(childNode);
};
var noise=[
[1,-1],
[0, -1],
[-1, 0],
[0, 1],
[0, 1],
[1,-1],
[0, -1],
[-1, 0],
[0, 1],
[0, 1],
[1,-1],
[0, -1],
[-1, 0],
[0, 1],
[0, 1],
[1,-1],
[0, -1],
[-1, 0],
[0, 1],
[0, 1],
[1,-1],
[0, -1],
[-1, 0],
[0, 1],
[0, 1],
[1,-1],
[0, -1],
[-1, 0],
[0, 1],
[0, 1],
];
var removeLayer = function(){
var that = this.parentNode
while(!that.classList.contains("snake-layer")){
that = that.parentNode;
}
that.parentNode.removeChild(that);
}
var NBlayers = 30
var layersDone = 0
var layerDone = function(){
layersDOne++;
if (layersDone >= NBlayers){
console.log("done");
}
}
for(var i = 0; i < NBlayers; i++){
(function(i){
setTimeout(function(){
var layer = document.createElement("div");
layer.className = "snake-layer";
container.appendFirst(layer);
var horiz = document.createElement("marquee");
horiz.setAttribute("direction","up");
horiz.setAttribute("behavior","alternate");
horiz.setAttribute("truespeed","");
horiz.setAttribute("scrollamount","8");
horiz.setAttribute("scrolldelay","25");
horiz.className ="snake-horiz";
allthemarquee.lvlup();
layer.appendChild(horiz);
var vert = document.createElement("marquee");
vert.setAttribute("direction","left");
vert.setAttribute("behavior","alternate");
vert.setAttribute("truespeed","");
vert.setAttribute("scrollamount","8");
vert.setAttribute("scrolldelay","25");
vert.className ="snake-vert";
allthemarquee.lvlup();
horiz.appendChild(vert);
var elem = document.createElement("div");
elem.className = "snake-elem";
vert.appendChild(elem);
var j = 0;
var noiseIntervalId = setInterval(function(){
vert.setAttribute("scrollamount", parseInt(vert.getAttribute("scrollamount")) + parseInt(noise[j][0])*3);
horiz.setAttribute("scrollamount", parseInt(horiz.getAttribute("scrollamount")) + parseInt(noise[j][1])*3);
j++;
if(j >= noise.length){
console.log("clearing interval" +noiseIntervalId);
clearInterval(noiseIntervalId);
}
}, 1000)
console.log("setting inteval :" + noiseIntervalId);
setTimeout(function(){
//vert.setAttribute("scrollamount",10+10*Math.random());
//vert.setAttribute("direction", Math.random() < 0.5 ? "left" : "right" );
vert.setAttribute("behavior","scroll");
vert.setAttribute("loop","1");
vert.addEventListener("finish", removeLayer);
//horiz.setAttribute("scrollamount",10+10*Math.random());
//horiz.setAttribute("direction", Math.random() < 0.5 ? "up": "down" );
horiz.setAttribute("behavior","scroll");
horiz.setAttribute("loop","1");
horiz.addEventListener("finish", removeLayer);
}, time-6000);
}, i*100);
})(i);
}
}