-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix-effect.js
51 lines (41 loc) · 1.43 KB
/
matrix-effect.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
window.onload = function () {
// Configurações
var matrixCanvas = document.getElementById('matrix-canvas');
var context = matrixCanvas.getContext('2d');
var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-=_+[]{}|;\':",./<>?`~';
var fontSize = 15;
var columns;
var drops = [];
// Configurações iniciais
function setup() {
matrixCanvas.width = window.innerWidth;
matrixCanvas.height = window.innerHeight;
columns = matrixCanvas.width / fontSize;
for (var x = 0; x < columns; x++) {
drops[x] = 1;
}
}
// Desenha os caracteres na tela
function draw() {
context.fillStyle = 'rgba(0, 0, 0, 0.05)';
context.fillRect(0, 0, matrixCanvas.width, matrixCanvas.height);
context.fillStyle = '#0F0';
context.font = fontSize + 'px arial';
for (var i = 0; i < drops.length; i++) {
var text = characters[Math.floor(Math.random() * characters.length)];
context.fillText(text, i * fontSize, drops[i] * fontSize);
if (drops[i] * fontSize > matrixCanvas.height && Math.random() > 0.975) {
drops[i] = 0;
}
drops[i]++;
}
}
// Loop de animação
function animate() {
draw();
requestAnimationFrame(animate);
}
// Inicializa o efeito de matriz
setup();
animate();
}