-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
198 lines (193 loc) · 8.8 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
<!--<![CDATA[
/**!
* SVG Particles (Site) example
* @author 0znzw https://scratch.mit.edu/users/0znzw/
* @version 1.4
* @copyright MIT License
* Do not remove this comment
* This does not apply to anything outside this file
*/
]]>-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG Particles</title>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
width: 100vw;
height: 100vh;
background: #333;
color: whitesmoke;
}
pre.erudaStatus {
margin-bottom: 7px;
}
input#seedInput {
width: fit-content;
}
a {
color: cornflowerblue;
}
a:hover {
color: cornflowerblue;
}
/* for other browsers that are not chrome */
:root *:not(svg) {
/* start transform origin */
transform-origin: 0px 0px;
/* firefox */
-moz-transform-origin: 0px 0px;
/* IE8 */
-ms-transform-origin: 0px 0px;
/* safari */
-webkit-transform-origin: 0px 0px;
/* opera */
-o-transform-origin: 0px 0px;
/* end transform origin */
}
svg:not(:root) {
overflow-clip-margin: content-box;
overflow: hidden;
}
</style>
</head>
<body>
<noscript>This site requires javascript to function.</noscript>
<script>
// <![CDATA[
(() => {
'use strict';
const constants = {
PI2: Math.PI * 2,
PI3: Math.PI * 3,
settings: [
15,
149.8,
56.7,
'7s',
// Thanks for the block path blockly!
'm 0,4 A 4,4 0 0,1 4,0 H 12 c 2,0 3,1 4,2 l 4,4 c 1,1 2,2 4,2 h 12 c 2,0 3,-1 4,-2 l 4,-4c 1,-1 2,-2 4,-2 H 143.55555725097656 a 4,4 0 0,1 4,4 v 40 a 4,4 0 0,1 -4,4 H 48 h 0c -2,0 -3,1 -4,2 l -4,4 c -1,1 -2,2 -4,2 h -12 c -2,0 -3,-1 -4,-2 l -4,-4c -1,-1 -2,-2 -4,-2 H 4 a 4,4 0 0,1 -4,-4 z',
],
};
const query = new URLSearchParams(window.location.search);
if (query.has('eruda')) {
document.head.appendChild((_ => {
const script = document.createElement('script');
script.onerror = e => {
console.error(e);
document.querySelector('pre.erudaStatus').textContent = `Failed to load eruda.\n${e.toString()}`;
alert('Failed to load eruda.');
};
script.onload = () => {
document.querySelector('pre.erudaStatus').style.display = 'none';
window['eruda'].init();
alert('Eruda should be loaded.');
};
script.src = 'https://cdn.jsdelivr.net/npm/eruda';
return script;
})());
}
window.ParticleTools_onLibraryLoad = function (generateAnimation) {
if (query.has('dev')) window.generateAnimation = generateAnimation;
const seed = query.has('testSeed') ? /*
Fun fact!
This number is the date I joined discord, on my new account, in the julian date format.
*/2460127 : Number(query.get('seed') || generateAnimation.randomInt(2147483647));
let positionAlgorithm = null;
if (query.has('cSHAPE-heart')) {
document.head.appendChild((_ => {
const styles = document.createElement('style');
styles.textContent = `
.demoTools-heart {
stroke: transparent !important;
stroke-width: 0px !important;
fill: url(#demoTools-particlesHeart) !important;
r: 6.283185307179586 !important;
/* 215�, 100%, 65% (Hi shima) */
--demoTools-hueHeartRotate: 215deg;
--demoTools-hueHeartSaturate: 100%;
--demoTools-hueHeartBrightness: 130%;
-webkit-filter: hue-rotate(var(--demoTools-hueHeartRotate)) saturate(var(--demoTools-hueHeartSaturate)) brightness(var(--demoTools-hueHeartBrightness));
-moz-filter: hue-rotate(var(--demoTools-hueHeartRotate)) saturate(var(--demoTools-hueHeartSaturate)) brightness(var(--demoTools-hueHeartBrightness));
-ms-filter: hue-rotate(var(--demoTools-hueHeartRotate)) saturate(var(--demoTools-hueHeartSaturate)) brightness(var(--demoTools-hueHeartBrightness));
filter: hue-rotate(var(--demoTools-hueHeartRotate)) saturate(var(--demoTools-hueHeartSaturate)) brightness(var(--demoTools-hueHeartBrightness));
}
`;
return styles;
})());
window.PARTICLETOOLS_CSHAPE = (sizeClass, id, speed) => (`
<g>
<circle data-particleAnimation="${id}" data-time="${speed}" class="particletools-particle demoTools-heart"></circle>
</g>
`);
window.PARTICLETOOLS_CSHAPE_DEFS = `
<pattern id="demoTools-particlesHeart" x="0" y="0" patternUnits="objectBoundingBox" width="100%" height="100%">
<image x="3.141592653589793" y="0" width="6.283185307179586" height="6.283185307179586" preserveAspectRatio="none" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBoZWlnaHQ9IjMxNSIgd2lkdGg9IjM0MiI+PGRlZnM+PCEtLSBodHRwczovL3VwbG9hZC53aWtpbWVkaWEub3JnL3dpa2lwZWRpYS9jb21tb25zLzgvODYvQV9wZXJmZWN0X1NWR19oZWFydC5zdmcgLS0+PHBhdGggZD0iTTAgMjAwVjBoMjAwYTEwMCAxMDAgOTAgMCAxIDAgMjAwIDEwMCAxMDAgOTAgMCAxLTIwMCAweiIgaWQ9ImEiLz48L2RlZnM+PHVzZSB4bGluazpocmVmPSIjYSIgZmlsbD0icmVkIiB0cmFuc2Zvcm09InJvdGF0ZSgyMjUgMTUwIDEyMSkiIHN0eWxlPSJzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MCIvPjwvc3ZnPg=="></image>
</pattern>
`;
}
if (query.has('alg-bubbleFest')) {
positionAlgorithm = (rng, width, height, id) => {
const sx = Math.round(rng.float() * width) + (((Math.round(rng.float()) === 0 ? -1 : 1)) * constants.PI2);
const ey = Math.round(rng.float() * width) + (((Math.round(rng.float()) === 0 ? -1 : 1)) * constants.PI2);
return { cssAnimation: `
from { cx: ${sx}; cy: ${height + constants.PI3} }
to { cx: ${ey}; cy: ${0 - constants.PI3} }
`, classCss: `${generateAnimation.writeAnimationProps(`
animation-duration: ${rng.range(1400, 2100)}ms !important;
animation-direction: forward !important;
`)}` };
};
} else if (query.has('alg-bubbleUp')) {
constants.settings[0] = 50;
positionAlgorithm = (rng, width, height, id) => {
const sx = Math.round(rng.float() * width) + (((Math.round(rng.float()) === 0 ? -1 : 1)) * constants.PI2);
const ex = Math.round(rng.float() * width) + (((Math.round(rng.float()) === 0 ? -1 : 1)) * constants.PI2);
const circleSpeed = rng.range(7000, 14000);
return { cssAnimation: `
from { cx: ${sx}; cy: ${height + constants.PI3} }
to { cx: ${ex}; cy: ${0 - constants.PI2} }
`, classCss: `${generateAnimation.writeAnimationProps(`
animation-duration: ${circleSpeed}ms !important;
animation-direction: normal !important;
animation-timing-function: linear !important;
animation-fill-mode: forwards !important;
animation-delay: ${rng.range(4000, 10000)}ms !important;
`)}`, speed: `${circleSpeed}ms` };
};
}
window.updateQuery = function () {
const newSeed = Number(
document.querySelector('input[data-id="seedInput"]').value ||
generateAnimation.randomInt(2147483647)
);
query.set('seed', String(Math.max(1, newSeed % 2147483648)));
window.location.search = query.toString();
};
const documentHTML = `
${(query.has('eruda') ? `
<pre class="erudaStatus">Loading eruda...</pre>
` : '')}
Seed: <input data-id="seedInput" type="number" min="1" max="2147483647" value="${seed}" />
<button onclick="window.updateQuery();">Go!</button>
<br />
<a href="https://github.com/surv-is-a-dev/SVG-Particles">This page is open source!</a>
<br />
`;
document.body.innerHTML = (documentHTML + generateAnimation(
seed,
...constants.settings,
positionAlgorithm
));
};
})();
// ]]>
</script>
<!-- Look at ./src-script.js for the OG code -->
<script src="./babel-script.js" type="application/javascript"></script>
<!-- Comment-->
</body>
</html>