Cheap Matrix Replacement
by dillmoody
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Animation</title>
</head>
<body>
<article class="digital-geography">
<h1 class="entry-title">Layer Extend and Share</h1>
</article>
</body>
</html>
CSS
body {
display: flex;
justify-content: left;
align-items: center;
height: 100vh;
margin: 0 0 0 2rem;
background-color: #222;
color: #00ff41;
font-family: Arial, sans-serif;
}
.digital-geography h1 {
font-size: 2rem;
letter-spacing: -0.1em;
text-transform: uppercase;
}
.digital-geography h1.entry-title::after {
content: "█";
width: 0.5em;
height: 1em;
color: #00ff41;
opacity: 1;
display: inline-block;
animation: cursor-blink 1.5s steps(10) infinite;
}
.random {
color: #00ff41;
}
@keyframes cursor-blink {
0%, 100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
JavaScript
matrixrain: {
if (!(document.getElementsByClassName("entry-title")[0] !== null)) {
break matrixrain;
}
const h1Element = document.getElementsByClassName("entry-title")[0];
const targetText = h1Element.innerText + ' ';
const characters = "ヲイクコソチトノフヤヨルレロンハミヒーウシナモニサワツオリアホテマケメエカキムユラセネスタヌヘABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()ƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃDŽDždžLJLjljNJNjnjǎǐǒǔǖǘǚǜǝǟǡǢǣǤǧǨǩǪǫǬǭǮǯǰDZDzdzǵǶǷǹヲイクコソチトノフヤヨルレロンハミヒーウシナモニサワツオリアホテマケメエカキムユラセネスタヌ";
let displayedText = Array.from({
length: targetText.length
}, () =>
characters[Math.floor(Math.random() * characters.length)]
); // Generate initial random string
let currentIndex = 0;
const updateDisplay = () => {
// Build the HTML string with spans for each character
const content = displayedText
.map((char, index) =>
index < currentIndex ?
`${char}` // Correct characters in white
:
`<span class="random">${char}</span>` // Random characters in green
)
.join("");
h1Element.innerHTML = content;
};
// Display the initial random string
updateDisplay();
const animateText = () => {
// Reveal the correct character at the current index
if (displayedText[currentIndex] !== targetText[currentIndex]) {
displayedText[currentIndex] = targetText[currentIndex];
}
// Randomize the remaining characters
for (let i = currentIndex + 1; i < targetText.length; i++) {
if (displayedText[i] !== targetText[i]) {
displayedText[i] = characters[Math.floor(Math.random() * characters.length)];
}
}
// Update the displayed text
updateDisplay();
// Move to the next character if the current one is correct
if (displayedText[currentIndex] ===...