Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Matrix Animation</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background-color: black;
        }
        canvas {
            display: block;
            margin: auto;
        }
    </style>
</head>
<body>
    <!-- Холст для анимации матрицы -->
    <canvas id="matrixCanvas" width="1000" height="800"></canvas>
    <!-- Подключение скрипта для анимации -->
    <script src="app.js"></script>
</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                // JavaScript код для создания анимации матрицы
const canvas = document.getElementById('matrixCanvas');
const ctx = canvas.getContext('2d');
const columns = 500; // Количество столбцов матрицы
const colWidth = canvas.width / columns; // Ширина каждого столбца
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; // Символы для анимации

let symbols = []; // Массив для хранения объектов Symbol

// Класс для символов, падающих по экрану
class Symbol {
    constructor(x, y, speed, symbol) {
        this.x = x; // Координата X
        this.y = y; // Координата Y
        this.speed = speed; // Скорость падения
        this.symbol = symbol; // Символ
    }

    // Метод для отрисовки символа
    draw() {
        ctx.fillStyle = '#0f0'; // Зеленый цвет
        ctx.font = '24px monospace'; // Шрифт
        ctx.fillText(this.symbol, this.x, this.y); // Отрисовка символа
    }

    // Метод для обновления положения символа
    update() {
        this.y += this.speed; // Обновление положения по Y
        if (this.y > canvas.height) { // Если символ вышел за пределы холста
            this.y = -20; // Перемещаем символ вверх
            this.speed = 2 + Math.random() * 2; // Случайное изменение скорости падения
        }
    }
}

// Функция для инициализации символов
function init() {
    for (let i = 0; i < columns; i++) {
        let x = i * colWidth + colWidth / 2; // Вычисление координаты X
        let y = Math.random() * canvas.height; // Случайная координата Y
        let speed = 2 + Math.random() * 2; // Случайная скорость падения
        let symbol = alphabet[Math.floor(Math.random() * alphabet.length)]; // Случайный символ
        symbols.push(new Symbol(x, y, speed, symbol)); // Добавляем символ в массив
    }
}

// Функция для отрисовки символов
function draw() {
    ctx.clearRect(0, 0, canvas.width, canvas.height); // Очистка холста
    symbols.forEach(symbol => {
        symbol.draw(); // Отрисовка каждого символа
    });
}

// Функция для обновления положения символов
function update() {
    symbols.forEach(symbol => {
        symbol.update(); // Обновление каждого символа
    });
}

// Функция для циклической анимации
function loop() {
    draw(); // Отрисовка
    update(); // Обновление
    requestAnimationFrame(loop); // Повторение анимации
}

// Инициализация и запуск анимации
init();
loop();

              
            
!
999px

Console