-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
120 lines (109 loc) · 2.82 KB
/
script.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
const lights = document.querySelectorAll("i");
lights.forEach((light) => {
light.style.animationDelay = `${Math.random() * -7000}ms`;
});
"use strict";
const COUNT = 150;
const SIZES = [
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--s",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--m",
"snowflake--l",
"snowflake--l",
"snowflake--l",
"snowflake--xl",
"snowflake--xl",
"snowflake--xl",
"snowflake--xl",
"snowflake--xl",
"snowflake--xl",
"snowflake--xl"
];
const EMOJI = ["❄️"];
const snowContainer = document.querySelector(".snow-container");
const genSnowflake = (size, xStart, xEnd, yStart, emoji, delay) => {
const s = document.createElement("div");
s.innerText = emoji;
s.classList.add("snowflake", size);
s.style.setProperty("--delay", delay + "ms");
s.style.setProperty("--x-start", xStart + "vw");
s.style.setProperty("--x-end", xEnd + "vw");
s.style.setProperty("--y-start", yStart + "vh");
s.style.setProperty("--y-end", yStart + 200 + "vh");
return s;
};
for (let i = 0; i < COUNT; i++) {
const size = randFromList(SIZES);
const xStart = getRandomArbitrary(0, 100);
const delay = i * 200;
const xEnd = getRandomArbitrary(xStart - 20, xStart + 20);
const emoji = randFromList(EMOJI);
const yStart = getRandomArbitrary(-100, 0);
snowContainer.appendChild(genSnowflake(size, xStart, xEnd, yStart, emoji, delay));
}
function randFromList(items) {
return items[Math.floor(Math.random() * items.length)];
}
function gaussianRand() {
var rand = 0;
for (var i = 0; i < 6; i += 0.25) {
rand += Math.random();
}
return rand / 6;
}
function randn_bm(min, max, skew = 1) {
let u = 0, v = 0;
while (u === 0)
u = Math.random();
while (v === 0)
v = Math.random();
let num = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
num = num / 10.0 + 0.5;
if (num > 1 || num < 0)
num = randn_bm(min, max, skew);
else {
num = Math.pow(num, skew);
num *= max - min;
num += min;
}
return num;
}
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}