matrix

Скрипт Матрица

Скрипт на языке разметки html. Матрица.

Создайте страницу в текстовом редакторе, например в блокноте.

Вставьте код. Сохраните файл matrix.html  и откройте его с помощью любого браузера.

У Вас получиться бегущий матричный код из нулей и единиц в 20 рядов.

<!DOCTYPE html>
<html>
<head>
<title>Matrix Effect</title>
<style>
body {
font-family: monospace;
background-color: black;
color: lime;
overflow: hidden;
}
</style>
</head>
<body>
<script>
const columns = 100;
const rows = 20;
const speed = 50;
let matrix = [];

for (let i = 0; i < columns * rows; i++) {
matrix[i] = Math.floor(Math.random() * 2);
}

// Вставляем "proneyroset.ru" в середину матрицы
const text = "proneyroset.ru";
const textLength = text.length;
const start = Math.floor((columns * rows - textLength) / 2);
for (let i = 0; i < textLength; i++) {
matrix[start + i] = 1;
}

function updateMatrix() {
for (let i = 0; i < columns * rows; i++) {
if (Math.floor(Math.random() * 10) === 1) {
matrix[i] = Math.floor(Math.random() * 2);
}
}
}

function drawMatrix() {
let output = '';
for (let i = 0; i < columns * rows; i++) {
output += matrix[i];
if ((i + 1) % columns === 0) {
output += '<br>';
}
}
document.body.innerHTML = output;
}

function mainLoop() {
updateMatrix();
drawMatrix();
setTimeout(mainLoop, speed);
}

mainLoop();
</script>
</body>
</html>

 

 

Ответы

Ваш адрес email не будет опубликован. Обязательные поля помечены *