50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
const canvas = document.getElementById('matrix-canvas');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
|
|
//const letters = 'ABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZABCDEFGHIJKLMNOPQRSTUVXYZ1234567890';
|
|
const letters = '日ハミヒーウシナモニサワツオリアホテマケメエカキムユラセネスタヌヘヲイクコソチトノフヤヨルレロン012345789ZTHEMATRIX:・."=*+-<>¦|╌çク̄'
|
|
const fontSize = 24;
|
|
const fontColor = '#0F0';
|
|
const backgroundColor = 'rgba(0, 0, 0, 0.05)';
|
|
const milisec = 80;
|
|
|
|
let columns = canvas.width / fontSize;
|
|
|
|
const drops = [];
|
|
for (let x = 0; x < columns; x++) {
|
|
drops[x] = 1;
|
|
}
|
|
|
|
function draw() {
|
|
ctx.fillStyle = backgroundColor;
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
ctx.fillStyle = fontColor;
|
|
ctx.font = fontSize + 'px arial';
|
|
|
|
for (let i = 0; i < drops.length; i++) {
|
|
const text = letters.charAt(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]++;
|
|
}
|
|
}
|
|
|
|
setInterval(draw, milisec);
|
|
|
|
window.addEventListener('resize', () => {
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
columns = canvas.width / fontSize;
|
|
drops.length = 0;
|
|
for (let x = 0; x < columns; x++) {
|
|
drops[x] = 1;
|
|
}
|
|
});
|