My personal site hosted @ https://indexx.dev
1var Confetti = function () {
2 var t = function () {
3 return function () {
4 this.gravity = 10,
5 this.particle_count = 75,
6 this.particle_size = 1,
7 this.explosion_power = 25,
8 this.destroy_target = !0,
9 this.fade = !1;
10 };
11 }(),
12 e = function () {
13 function e(n) {
14 var r = this;
15 if (
16 this.bursts = [],
17 this.setCount = function (t) {
18 if ("number" != typeof t) {
19 throw new Error(
20 "Input must be of type 'number'",
21 );
22 }
23 e.CONFIG.particle_count = t;
24 },
25 this.setPower = function (t) {
26 if ("number" != typeof t) {
27 throw new Error(
28 "Input must be of type 'number'",
29 );
30 }
31 e.CONFIG.explosion_power = t;
32 },
33 this.setSize = function (t) {
34 if ("number" != typeof t) {throw new Error(
35 "Input must be of type 'number'",
36 );}
37 e.CONFIG.particle_size = t;
38 },
39 this.setFade = function (t) {
40 if ("boolean" != typeof t) {
41 throw new Error(
42 "Input must be of type 'boolean'",
43 );
44 }
45 e.CONFIG.fade = t;
46 },
47 this.destroyTarget = function (t) {
48 if ("boolean" != typeof t) {throw new Error(
49 "Input must be of type 'boolean'",
50 );}
51 e.CONFIG.destroy_target = t;
52 },
53 this.setupCanvasContext = function () {
54 if (!e.CTX) {
55 var t = document.createElement("canvas");
56 e.CTX = t.getContext("2d"),
57 t.width = 2 * window.innerWidth,
58 t.height = 2 * window.innerHeight,
59 t.style.position = "fixed",
60 t.style.top = "0",
61 t.style.left = "0",
62 t.style.width = "calc(100%)",
63 t.style.height = "calc(100%)",
64 t.style.margin = "0",
65 t.style.padding = "0",
66 t.style.zIndex = "999999999",
67 t.style.pointerEvents = "none",
68 document.body.appendChild(t),
69 window.addEventListener("resize", function () {
70 t.width = 2 * window.innerWidth,
71 t.height = 2 * window.innerHeight;
72 });
73 }
74 },
75 this.setupElement = function (t) {
76 var n;
77 r.element = document.getElementById(t),
78 null === (n = r.element) || void 0 === n ||
79 n.addEventListener("click", function (t) {
80 var n = new o(2 * t.clientX, 2 * t.clientY);
81 r.bursts.push(new i(n)),
82 e.CONFIG.destroy_target &&
83 (r.element.style.visibility = "hidden");
84 });
85 },
86 this.update = function (t) {
87 r.delta_time = (t - r.time) / 1e3, r.time = t;
88 for (var e = r.bursts.length - 1; e >= 0; e--) {
89 r.bursts[e].update(r.delta_time),
90 0 == r.bursts[e].particles.length && r.bursts.splice(e, 1);
91 }
92 r.draw(), window.requestAnimationFrame(r.update);
93 },
94 !n
95 ) throw new Error("Missing id");
96 e.CONFIG || (e.CONFIG = new t()),
97 this.time = (new Date()).getTime(),
98 this.delta_time = 0,
99 this.setupCanvasContext(),
100 this.setupElement(n),
101 window.requestAnimationFrame(this.update);
102 }
103 return e.prototype.draw = function () {
104 s.clearScreen();
105 for (var t = 0, e = this.bursts; t < e.length; t++) e[t].draw();
106 },
107 e;
108 }(),
109 i = function () {
110 function t(t) {
111 this.particles = [];
112 for (var i = 0; i < e.CONFIG.particle_count; i++) {
113 this.particles.push(new n(t));
114 }
115 }
116 return t.prototype.update = function (t) {
117 for (var e = this.particles.length - 1; e >= 0; e--) {
118 this.particles[e].update(t),
119 this.particles[e].checkBounds() && this.particles.splice(e, 1);
120 }
121 },
122 t.prototype.draw = function () {
123 for (var t = this.particles.length - 1; t >= 0; t--) {
124 this.particles[t].draw();
125 }
126 },
127 t;
128 }(),
129 n = function () {
130 function t(t) {
131 this.size = new o(
132 (16 * Math.random() + 4) * e.CONFIG.particle_size,
133 (4 * Math.random() + 4) * e.CONFIG.particle_size,
134 ),
135 this.position = new o(t.x - this.size.x / 2, t.y - this.size.y / 2),
136 this.velocity = r.generateVelocity(),
137 this.rotation = 360 * Math.random(),
138 this.rotation_speed = 10 * (Math.random() - .5),
139 this.hue = 360 * Math.random(),
140 this.opacity = 100,
141 this.lifetime = Math.random() + .25;
142 }
143 return t.prototype.update = function (t) {
144 this.velocity.y += e.CONFIG.gravity *
145 (this.size.y / (10 * e.CONFIG.particle_size)) * t,
146 this.velocity.x += 25 * (Math.random() - .5) * t,
147 this.velocity.y *= .98,
148 this.velocity.x *= .98,
149 this.position.x += this.velocity.x,
150 this.position.y += this.velocity.y,
151 this.rotation += this.rotation_speed,
152 e.CONFIG.fade && (this.opacity -= this.lifetime);
153 },
154 t.prototype.checkBounds = function () {
155 return this.position.y - 2 * this.size.x > 2 * window.innerHeight;
156 },
157 t.prototype.draw = function () {
158 s.drawRectangle(
159 this.position,
160 this.size,
161 this.rotation,
162 this.hue,
163 this.opacity,
164 );
165 },
166 t;
167 }(),
168 o = function () {
169 return function (t, e) {
170 this.x = t || 0, this.y = e || 0;
171 };
172 }(),
173 r = function () {
174 function t() {}
175 return t.generateVelocity = function () {
176 var t = Math.random() - .5,
177 i = Math.random() - .7,
178 n = Math.sqrt(t * t + i * i);
179 return i /= n,
180 new o(
181 (t /= n) * (Math.random() * e.CONFIG.explosion_power),
182 i * (Math.random() * e.CONFIG.explosion_power),
183 );
184 },
185 t;
186 }(),
187 s = function () {
188 function t() {}
189 return t.clearScreen = function () {
190 e.CTX &&
191 e.CTX.clearRect(0, 0, 2 * window.innerWidth, 2 * window.innerHeight);
192 },
193 t.drawRectangle = function (t, i, n, o, r) {
194 e.CTX &&
195 (e.CTX.save(),
196 e.CTX.beginPath(),
197 e.CTX.translate(t.x + i.x / 2, t.y + i.y / 2),
198 e.CTX.rotate(n * Math.PI / 180),
199 e.CTX.rect(-i.x / 2, -i.y / 2, i.x, i.y),
200 e.CTX.fillStyle = "hsla(" + o + "deg, 90%, 65%, " + r + "%)",
201 e.CTX.fill(),
202 e.CTX.restore());
203 },
204 t;
205 }();
206 return e;
207}();