Matrix HTML-background

https://cyberdream.se/matrix/index.htm

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CYBERDREAM Vertical Freeze</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background: black;
        }
        canvas {
            display: block;
        }
    </style>
</head>
<body>
    <canvas id="matrix"></canvas>
    <script>
        // Get the canvas element
        const canvas = document.getElementById('matrix');
        const ctx = canvas.getContext('2d');

        // Set canvas dimensions
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;

        // Characters for the Matrix effect
        const chars = ' ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ1234567890@£${[]}\<>§½*üÜïϨëËõÕ~ãÃâÂôÔÊêÎî|_+!"#¤%%&/()=?`abcdefghijklmnopqrstuvwxyzåäö';
        const targetWord = "FOLLOW.THE.WHITE.RABBIT".split('');
        const charArray = chars.split('');
        const fontSize = 14;

        // Calculate columns
        const columns = canvas.width / fontSize;
        const drops = Array(Math.floor(columns)).fill(1);

        // Track frozen sequences
        const frozenSequences = [];

        // Draw function
        function draw() {
            ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
            ctx.fillRect(0, 0, canvas.width, canvas.height);

            ctx.fillStyle = '#0F0';
            ctx.font = `${fontSize}px monospace`;

            for (let i = 0; i < drops.length; i++) {
                const x = i * fontSize;
                const y = drops[i] * fontSize;

                // Check if this column has a frozen sequence
                const frozenSequence = frozenSequences.find((f) => f.column === i);

                if (frozenSequence) {
                    // Draw the frozen sequence and skip this column
                    frozenSequence.letters.forEach((letter, index) => {
                        ctx.fillText(letter.char, x, letter.y);
                    });
                    continue;
                }

                // Get a random character
                const text = charArray[Math.floor(Math.random() * charArray.length)];

                // Draw the character
                ctx.fillText(text, x, y);

                // Randomly freeze a vertical "CYBERDREAM" sequence
                if (text === 'C' && Math.random() < 0.002 && drops[i] + targetWord.length < canvas.height / fontSize) {
                    const sequence = targetWord.map((char, idx) => ({
                        char: char,
                        y: (drops[i] + idx) * fontSize
                    }));
                    frozenSequences.push({ column: i, letters: sequence });
                }

                // Reset drop if it goes off screen
                if (y > canvas.height && Math.random() > 0.975) {
                    drops[i] = 0;
                }

                drops[i]++;
            }
        }

        // Loop the animation
        setInterval(draw, 38);

        // Adjust canvas on resize
        window.addEventListener('resize', () => {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
        });
    </script>
</body>
</html>

Post a Reply