-
Notifications
You must be signed in to change notification settings - Fork 24
/
bubbles.js
230 lines (207 loc) · 11.8 KB
/
bubbles.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
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
var rando = (n) => Math.round(Math.random() * n);
var delay = (ms) => new Promise(res => setTimeout(res, ms));
var ele = (t) => document.createElement(t);
var attr = (o, k, v) => o.setAttribute(k, v);
var tn = (o, s) => o ? o.getElementsByTagName(s) : console.log(o);
var cn = (o, s) => o ? o.getElementsByClassName(s) : console.log(o);
var gi = (o, s) => o ? o.getElementById(s) : console.log(o);
function genColor(n) {
var s = '';
var chars = '1e043579bd';
for (var i = 0; i <= n; i++) {
s += chars[rando(9)];
}
return s;
}
function randomBalls() {
var colors = ['#ff1a0a','#ff430a','#ff6a00','#ffa463','#ffceab','#ffe0ab','#ffc157','#ffa50a','#ffc60a','#ffd64f','#ffe17d','#fff1c4','#fff1c4','#ffd036','#ffc300','#ffc300','#fff694','#ffee36','#fff836','#fffdd1','#d1ffff','#42ffff','#42ffff','#e0ffff','#e0f9ff','#12d1ff','#12d1ff','#d4f6ff','#d4ecff','#57b3ff','#0f93ff','#0f93ff','#0f67ff','#f2ebff','#733dd9','#5800ff','#5800ff','#b187ff','#c978ff','#c978ff','#fdedff','#ffedff','#ff00ff','#ff00c8','#ffe6fa','#ff009d','#ff0044','#ffc7d6','#ff002f','#ffdbe2','#ff2638'];
var circles = ``;
for (var i = 0; i < 350; i++) {
var startPos = 100;
var startRad = rando(6) / 10;
var endRad = rando(10) / 10;
var x = rando(180);
var y = rando(160);
var altColor = colors[rando((colors.length-1))];
var color = `#${genColor(5)}`;
var time = (rando(20) / 10);
circles += `<circle class="bubbles" cx="${x}" cy="${y}" r="${startRad}" fill="${altColor}">
<animate attributeName="fill" values="${color}; ${altColor}; ${altColor};" begin="0s" dur="${time}s" repeatCount="0" />
<animate attributeName="cy" values="${startPos}; ${y-(y/10)}; ${y}; ${y};" begin="0s" dur="${time}s" repeatCount="0" />
<animate attributeName="r" values="${startRad}; ${endRad}; ${endRad-(endRad/10)}; ${startRad};" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="cx" values="${startPos}; ${x-(x/10)}; ${x}; ${x};" begin="0s" dur="${time}s" repeatCount="0" />
</circle>`;
}
return circles;
}
function killthis(){
this.outerHTML = '';
}
function resetPos(){
var circles = Array.from(cn(document,'bubbles'));
for(var c=0; c<circles.length; c++){
var elm = circles[c];
var p = ['','-','','-','','-'];
var x = p[rando(6)];
var y = p[rando(6)];
elm.style.transform = `translate(${x+rando(60)}px, ${y+rando(60)}px)`;
elm.style.transition = `all ${rando(600)}ms ease-in-out`;
}
}
function celebrate() {
if(gi(document,'celebrationParent')) gi(document,'celebrationParent').outerHTML = '';
var balls = randomBalls();
var sv = ele('div');
attr(sv,'id','celebrationParent');
attr(sv,'style','position: fixed; z-index: 11111; top: 20%; left: 20%; width: 500px; height: 500px; background: #000; clip-path: circle(30%);');
document.body.appendChild(sv);
sv.innerHTML = `<svg viewBox="0 0 220 220">${balls}</svg>`;
sv.onclick = resetPos;
// sv.outerHTML = ''
}
celebrate()
// altversion
var rando = (n) => Math.round(Math.random() * n);
var delay = (ms) => new Promise(res => setTimeout(res, ms));
var ele = (t) => document.createElement(t);
var attr = (o, k, v) => o.setAttribute(k, v);
var tn = (o, s) => o ? o.getElementsByTagName(s) : console.log(o);
var cn = (o, s) => o ? o.getElementsByClassName(s) : console.log(o);
var gi = (o, s) => o ? o.getElementById(s) : console.log(o);
function randomBalls() {
var colors = ["#e3f8ff","#e3f0ff","#d4f4ff","#d6e9ff","#d6f5ff","#cfe4ff","#ccf0fc","#c4f0ff","#c2ddff","#baedff","#b5d6ff","#b0ebff","#a6e8ff","#91e3ff","#195db0","#4599ff","#4564ff","#6982ff","#879bff","#bac6ff","#c5cefc","#e6eaff","#c8c4ff","#e5e3ff",'#ff1a0a','#ff430a','#ff6a00','#ffa463','#ffceab','#ffe0ab','#ffc157','#ffa50a','#ffc60a','#ffd64f','#ffe17d','#fff1c4','#fff1c4','#ffd036','#ffc300','#ffc300','#fff694','#ffee36','#fff836','#fffdd1','#d1ffff','#42ffff','#42ffff','#e0ffff','#e0f9ff','#12d1ff','#12d1ff','#d4f6ff','#d4ecff','#57b3ff','#0f93ff','#0f93ff','#0f67ff','#f2ebff','#733dd9','#5800ff','#5800ff','#b187ff','#c978ff','#c978ff','#fdedff','#ffedff','#ff00ff','#ff00c8','#ffe6fa','#ff009d','#ff0044','#ffc7d6','#ff002f','#ffdbe2','#ff2638'];
var circles = ``;
for (var i = 0; i < 350; i++) {
var startPos = 110;
var startRad = rando(6) / 10;
var endRad = rando(10) / 10;
var x = rando(180);
var y = rando(180);
var altColor = colors[rando((colors.length-1))];
var color = colors[rando((colors.length-1))];
var time = (rando(50) / 10);
circles += `<circle class="bubbles" cx="${x}" cy="${y}" r="${startRad}" fill="${altColor}">
<animate attributeName="fill" values="${color}; ${altColor}; ${altColor};" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="cy" values="${startPos}; ${y-(y/10)}; ${y}; ${startPos-(y/10)}; ${startPos}" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="r" values="${startRad}; ${endRad}; ${endRad-(endRad/10)}; ${startRad};" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="cx" values="${startPos}; ${x-(x/10)}; ${x}; ${startPos-(x/10)}; ${startPos}" begin="0s" dur="${time}s" repeatCount="indefinite" />
</circle>`;
}
return circles;
}
async function killthis(){
gi(document,'celebrationParent').style.transform = 'scale(0.1, 0.1)';
gi(document,'celebrationParent').style.transition = 'all 700ms';
await delay(699);
gi(document,'celebrationParent').outerHTML = '';
}
async function celebrate() {
if(gi(document,'celebrationParent')) gi(document,'celebrationParent').outerHTML = '';
var balls = randomBalls();
var sv = ele('div');
attr(sv,'id','celebrationParent');
attr(sv,'style','position: fixed; z-index: 21111; top: 20%; left: 20%; width: 800px; height: 800px; background: transparent; clip-path: circle(30%);');
document.body.appendChild(sv);
sv.innerHTML = `<svg viewBox="0 0 220 220">${balls}</svg>`;
sv.onclick = killthis;
await delay(5009);
killthis();
}
celebrate();
//2nd alternate
var rando = (n) => Math.round(Math.random() * n);
var delay = (ms) => new Promise(res => setTimeout(res, ms));
var ele = (t) => document.createElement(t);
var attr = (o, k, v) => o.setAttribute(k, v);
var tn = (o, s) => o ? o.getElementsByTagName(s) : console.log(o);
var cn = (o, s) => o ? o.getElementsByClassName(s) : console.log(o);
var gi = (o, s) => o ? o.getElementById(s) : console.log(o);
function randomBalls() {
var colors = ["#e3f8ff","#e3f0ff","#d4f4ff","#d6e9ff","#d6f5ff","#cfe4ff","#ccf0fc","#c4f0ff","#c2ddff","#baedff","#b5d6ff","#b0ebff","#a6e8ff","#91e3ff","#195db0","#4599ff","#4564ff","#6982ff","#879bff","#bac6ff","#c5cefc","#e6eaff","#c8c4ff","#e5e3ff",'#ff1a0a','#ff430a','#ff6a00','#ffa463','#ffceab','#ffe0ab','#ffc157','#ffa50a','#ffc60a','#ffd64f','#ffe17d','#fff1c4','#fff1c4','#ffd036','#ffc300','#ffc300','#fff694','#ffee36','#fff836','#fffdd1','#d1ffff','#42ffff','#42ffff','#e0ffff','#e0f9ff','#12d1ff','#12d1ff','#d4f6ff','#d4ecff','#57b3ff','#0f93ff','#0f93ff','#0f67ff','#f2ebff','#733dd9','#5800ff','#5800ff','#b187ff','#c978ff','#c978ff','#fdedff','#ffedff','#ff00ff','#ff00c8','#ffe6fa','#ff009d','#ff0044','#ffc7d6','#ff002f','#ffdbe2','#ff2638'];
var circles = ``;
for (var i = 0; i < 850; i++) {
var startPos = 110;
var startRad = rando(6) / 10;
var endRad = rando(10) / 10;
var x = rando(180);
var y = rando(180);
var altColor = colors[rando((colors.length-1))];
var color = colors[rando((colors.length-1))];
var time = ((rando(50)+2) / 10);
circles += `<circle class="bubbles" cx="${x}" cy="${y}" r="${startRad}" fill="${altColor}">
<animate attributeName="fill" values="${color}; ${altColor}; ${altColor};" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="cy" values="${startPos}; ${y-(y/10)}; ${y}; ${startPos-(y/15)}; ${startPos}" begin="0s" dur="${time}s" repeatCount="0" />
<animate attributeName="r" values="${startRad}; ${endRad}; ${endRad-(endRad/10)}; ${startRad};" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="cx" values="${startPos}; ${x-(x/10)}; ${x}; ${startPos-(x/10)}; ${startPos}" begin="0s" dur="${time}s" repeatCount="0" />
</circle>`;
}
return circles;
}
async function killthis(){
gi(document,'celebrationParent').style.transform = 'scale(0.1, 0.1)';
gi(document,'celebrationParent').style.transition = 'all 700ms';
await delay(699);
gi(document,'celebrationParent').outerHTML = '';
}
async function celebrate() {
if(gi(document,'celebrationParent')) gi(document,'celebrationParent').outerHTML = '';
var balls = randomBalls();
var sv = ele('div');
attr(sv,'id','celebrationParent');
attr(sv,'style','position: fixed; z-index: 21111; top: 20%; left: 20%; width: 800px; height: 800px; background: #000; clip-path: circle(30%);');
document.body.appendChild(sv);
sv.innerHTML = `<svg viewBox="0 0 220 220">${balls}</svg>`;
sv.onclick = killthis;
await delay(5009);
// killthis();
}
celebrate();
//3rd alternate. Big Bang
var rando = (n) => Math.round(Math.random() * n);
var delay = (ms) => new Promise(res => setTimeout(res, ms));
var ele = (t) => document.createElement(t);
var attr = (o, k, v) => o.setAttribute(k, v);
var tn = (o, s) => o ? o.getElementsByTagName(s) : console.log(o);
var cn = (o, s) => o ? o.getElementsByClassName(s) : console.log(o);
var gi = (o, s) => o ? o.getElementById(s) : console.log(o);
function randomBalls() {
var colors = ["#e3f8ff","#e3f0ff","#d4f4ff","#d6e9ff","#d6f5ff","#cfe4ff","#ccf0fc","#c4f0ff","#c2ddff","#baedff","#b5d6ff","#b0ebff","#a6e8ff","#91e3ff","#195db0","#4599ff","#4564ff","#6982ff","#879bff","#bac6ff","#c5cefc","#e6eaff","#c8c4ff","#e5e3ff",'#ff1a0a','#ff430a','#ff6a00','#ffa463','#ffceab','#ffe0ab','#ffc157','#ffa50a','#ffc60a','#ffd64f','#ffe17d','#fff1c4','#fff1c4','#ffd036','#ffc300','#ffc300','#fff694','#ffee36','#fff836','#fffdd1','#d1ffff','#42ffff','#42ffff','#e0ffff','#e0f9ff','#12d1ff','#12d1ff','#d4f6ff','#d4ecff','#57b3ff','#0f93ff','#0f93ff','#0f67ff','#f2ebff','#733dd9','#5800ff','#5800ff','#b187ff','#c978ff','#c978ff','#fdedff','#ffedff','#ff00ff','#ff00c8','#ffe6fa','#ff009d','#ff0044','#ffc7d6','#ff002f','#ffdbe2','#ff2638'];
var circles = ``;
for (var i = 0; i < 400; i++) {
var startPos = 110;
var startRad = rando(6) / 10;
var endRad = rando(10) / 10;
var x = rando(180);
var y = rando(180);
var altColor = colors[rando((colors.length-1))];
var color = colors[rando((colors.length-1))];
var time = ((rando(50)+2) / 10);
circles += `<circle class="bubbles" cx="${x > 120 && y >120 ? x-30 : x}" cy="${x > 120 && y >120 ? y-20 : y}" r="${startRad}" fill="${altColor}">
<animate attributeName="fill" values="${color}; ${altColor}; ${altColor};" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="cy" values="${startPos}; ${y};" begin="0s" dur="${time}s" repeatCount="0" />
<animate attributeName="r" values="${startRad}; ${endRad}; ${endRad-(endRad/10)}; ${startRad};" begin="0s" dur="${time}s" repeatCount="indefinite" />
<animate attributeName="cx" values="${startPos}; ${x};" begin="0s" dur="${time}s" repeatCount="0" />
</circle>`;
}
return circles;
}
async function killthis(){
gi(document,'celebrationParent').style.transform = 'scale(0.01, 0.01)';
gi(document,'celebrationParent').style.transition = 'all 500ms';
await delay(499);
gi(document,'celebrationParent').outerHTML = '';
celebrate()
}
async function celebrate() {
if(gi(document,'celebrationParent')) gi(document,'celebrationParent').outerHTML = '';
var balls = randomBalls();
var sv = ele('div');
attr(sv,'id','celebrationParent');
attr(sv,'style','position: fixed; z-index: 21111; top: 20%; left: 20%; width: 800px; height: 800px; background: #000; clip-path: circle(30%);');
document.body.appendChild(sv);
sv.innerHTML = `<svg viewBox="0 0 220 220">${balls}</svg>`;
sv.onclick = killthis;
await delay(5009);
// killthis();
}
celebrate();