A Pen by Ganesh Prasad on CodePen.
Created
May 10, 2022 13:52
-
-
Save white-label-development/53cc2262ec8f0ed9d768e5aea9dba5a9 to your computer and use it in GitHub Desktop.
Matrix Effect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canvas(id='canv', width=500, height=200) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.getElementById('canv'); | |
const ctx = canvas.getContext('2d'); | |
const w = canvas.width = document.body.offsetWidth; | |
const h = canvas.height = document.body.offsetHeight; | |
const cols = Math.floor(w / 20) + 1; | |
const ypos = Array(cols).fill(0); | |
ctx.fillStyle = '#000'; | |
ctx.fillRect(0, 0, w, h); | |
function matrix () { | |
ctx.fillStyle = '#0001'; | |
ctx.fillRect(0, 0, w, h); | |
ctx.fillStyle = '#0f0'; | |
ctx.font = '15pt monospace'; | |
ypos.forEach((y, ind) => { | |
const text = String.fromCharCode(Math.random() * 128); | |
const x = ind * 20; | |
ctx.fillText(text, x, y); | |
if (y > 100 + Math.random() * 10000) ypos[ind] = 0; | |
else ypos[ind] = y + 20; | |
}); | |
} | |
setInterval(matrix, 50); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0; | |
height: 100vh; | |
width: 100vw; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment