Skip to content

Commit 650b5ed

Browse files
author
Paul Adams
committed
More sparkles
1 parent aff7dac commit 650b5ed

1 file changed

Lines changed: 70 additions & 17 deletions

File tree

app.js

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,31 @@ const matrixEffect = (canvasId, containerSelector) => {
157157
canvas.height = container.offsetHeight;
158158

159159
const matrix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789@#$%^&*()*&^%";
160+
const sparkleText = [
161+
"code",
162+
"hack",
163+
"0xFF",
164+
"0x90",
165+
"xor",
166+
"eax",
167+
"lulz",
168+
"pwn",
169+
];
170+
171+
const vec2 = (x, y) => ({ x, y });
160172
const font_size = 10;
161173

162174
const circle_buffer_width = canvas.width / font_size;
163175
const circle_buffer_height = canvas.height / font_size;
164176
const columns = canvas.width / font_size;
165177
const drops = [];
166178
const particles = [];
179+
const lines = [];
167180
const circle_buffer = new Int8Array(
168181
circle_buffer_width * circle_buffer_height
169182
);
170183

171-
const maxParticles = 6;
184+
const maxParticles = 12;
172185

173186
for (let x = 0; x < columns; x++) {
174187
drops[x] = 1;
@@ -180,8 +193,8 @@ const matrixEffect = (canvasId, containerSelector) => {
180193
particles.push({
181194
x: Math.random() * canvas.width,
182195
y: Math.random() * canvas.height,
183-
radius: Math.random() * 50 + 75,
184-
speed: Math.random() * 4,
196+
radius: Math.random() * 170 + 25,
197+
speed: Math.random() * 6,
185198
dir: vec2(Math.random() - 0.5, Math.random() - 0.5),
186199
});
187200
}
@@ -267,7 +280,6 @@ const matrixEffect = (canvasId, containerSelector) => {
267280
}
268281

269282
function drawCicleBuffer() {
270-
ctx.fillStyle = "rgba(3, 94, 3, 1)";
271283
for (let y = 0; y < circle_buffer_height; y++) {
272284
for (let x = 0; x < circle_buffer_width; x++) {
273285
const index = (y * circle_buffer_width + x) | 0;
@@ -276,20 +288,30 @@ const matrixEffect = (canvasId, containerSelector) => {
276288
if (circle_buffer[index] > 0) {
277289
ctx.fillStyle = "rgba(0, 0, 0, 1)";
278290
ctx.fillRect(xx, yy, font_size, font_size);
279-
ctx.fillStyle = "rgba(5, 130, 5, 1)";
291+
if (circle_buffer[index] === 2) {
292+
ctx.fillStyle = "rgba(122, 5, 5, 1)";
293+
} else {
294+
ctx.fillStyle = "rgba(5, 130, 5, 1)";
295+
}
296+
280297
const text = matrix[Math.floor(Math.random() * matrix.length)];
281298
ctx.fillText(text, xx, yy + font_size);
282299
}
283300
}
284301
}
285302
}
286303

304+
function rndInt(min, max) {
305+
return Math.floor(Math.random() * (max - min + 1)) + min;
306+
}
307+
287308
function draw(deltaTime) {
288309
ctx.fillStyle = "rgba(0, 0, 0, 0.05)";
289310
ctx.fillRect(0, 0, canvas.width, canvas.height);
290311

291312
// Set the fill color to green
292313
ctx.fillStyle = "green";
314+
ctx.font = font_size + "px arial";
293315

294316
circle_buffer.fill(0);
295317

@@ -302,19 +324,37 @@ const matrixEffect = (canvasId, containerSelector) => {
302324
bresenhamCircle(p.x, p.y, p.radius);
303325
if (Math.random() < 0.01) {
304326
p.dir = vec2(Math.random() - 0.5, Math.random() - 0.5);
327+
p.radius = Math.random() * 100 + 25;
328+
}
329+
if (rndInt(0, 1000) < 5) {
330+
p.radius += Math.random() * 50 - 25;
331+
}
332+
333+
if (rndInt(0, 1000) < 10) {
334+
ctx.fillStyle = "rgba(233, 241, 244, 1)";
335+
ctx.fillText(sparkleText[rndInt(0, sparkleText.length - 1)], p.x, p.y);
336+
}
337+
}
338+
339+
if (lines.length === 0 && rndInt(0, 100) < 10) {
340+
const numLines = rndInt(2, maxParticles);
341+
for (let i = 0; i < numLines; i++) {
342+
lines.push(rndInt(0, maxParticles - 1));
343+
}
344+
}
345+
346+
if (lines.length >= 2) {
347+
for (let i = 0; i < lines.length - 1; i++) {
348+
const p1 = particles[lines[i]];
349+
const p2 = particles[lines[i + 1]];
350+
line(p1.x, p1.y, p2.x, p2.y);
351+
}
352+
if (rndInt(0, 1000) < 20) {
353+
lines.length = 0;
305354
}
306-
// if (i > 0) {
307-
// line(
308-
// particles[i - 1].x,
309-
// particles[i - 1].y,
310-
// particles[i].x,
311-
// particles[i].y
312-
// );
313-
// }
314355
}
315356

316357
ctx.fillStyle = "rgba(3, 94, 3, 1)";
317-
ctx.font = font_size + "px arial";
318358

319359
drawCicleBuffer();
320360
for (let i = 0; i < drops.length; i++) {
@@ -330,9 +370,22 @@ const matrixEffect = (canvasId, containerSelector) => {
330370
const index = (cy * circle_buffer_width + cx) | 0;
331371
if (circle_buffer[index] === 1) {
332372
ctx.fillStyle = "rgba(18, 215, 202, 1)";
333-
ctx.fillText("code", tx, ty);
334-
ctx.fillText("base", tx + font_size, ty + font_size);
335-
ctx.fillText("hack", tx - font_size, ty + font_size);
373+
ctx.fillText(sparkleText[rndInt(0, sparkleText.length - 1)], tx, ty);
374+
ctx.fillText(
375+
sparkleText[rndInt(0, sparkleText.length - 1)],
376+
tx + font_size,
377+
ty + font_size
378+
);
379+
ctx.fillText(
380+
sparkleText[rndInt(0, sparkleText.length - 1)],
381+
tx - font_size,
382+
ty + font_size
383+
);
384+
}
385+
if (circle_buffer[index] === 2) {
386+
ctx.fillStyle = "rgba(215, 18, 18, 1)";
387+
ctx.fillText("FF", tx + font_size, ty + font_size);
388+
ctx.fillText("90", tx - font_size, ty + font_size);
336389
}
337390
ctx.fillStyle = "rgba(3, 94, 3, 1)";
338391

0 commit comments

Comments
 (0)