-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (39 loc) · 1.92 KB
/
script.js
File metadata and controls
43 lines (39 loc) · 1.92 KB
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
window.addEventListener('DOMContentLoaded', function() {
// Matrix rain effect
const canvas = document.getElementById('matrix-canvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resizeCanvas();
const letters = 'アァイィウヴエェオカガキギクグケゲコゴサザシジスズセゼソゾタダチッヂヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモヤユヨラリルレロワヲンABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const fontSize = 18;
let columns = Math.floor(canvas.width / fontSize);
// Randomize initial drop positions for each column
let drops = Array.from({length: columns}, () => Math.floor(Math.random() * canvas.height / fontSize));
function draw() {
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.font = fontSize + 'px Courier New';
ctx.fillStyle = 'rgba(0, 255, 65, .25)'; // 1 is fully opaque, lower values are more transparent
for (let i = 0; i < drops.length; i++) {
const text = letters[Math.floor(Math.random() * letters.length)];
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) {
drops[i] = 0;
}
drops[i]++;
}
}
let intervalId = setInterval(draw, 50);
window.addEventListener('resize', function() {
clearInterval(intervalId);
resizeCanvas();
columns = Math.floor(canvas.width / fontSize);
// Randomize initial drop positions for each column on resize
drops = Array.from({length: columns}, () => Math.floor(Math.random() * canvas.height / fontSize));
intervalId = setInterval(draw, 50);
});
});