<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="bg"></canvas>
<script>
const cvs =document.getElementById('bg')
const width =window.innerWidth,
height = window.innerHeight;
cvs.width =width
cvs.height =height
const ctx = cvs.getContext("2d");
const columnWidth = 20;
const cloumnCount = Math.floor(window.innerWidth / columnWidth)
const columnNextIndexs = new Array(cloumnCount)
columnNextIndexs.fill(1)
function draw(){
ctx.fillStyle = 'rgba(240,240,240,.1)'
ctx.fillRect(0, 0,width,height)
const fz = 20;
ctx.fillStyle = getRandomColor()
ctx.font = `${fz}px "Roboto Mono"`
for (var i = 0; i <cloumnCount;i++) {
const x = i * columnWidth
const y = fz * columnNextIndexs[i]
ctx.fillText(getRandomChar(),x,y)
columnNextIndexs[i] ++
if(y >height && Math.random()>0.99 ){
columnNextIndexs[i] = 0
}else{
columnNextIndexs[i]++
}
}
}
function getRandomColor(){
const fontColors= [
'#33B5E5',
'#0099CC',
'#AA66CC',
'#9933CC',
'#99CC00',
'#669900',
'#FFBB33',
'#FF8800',
'#FF4444',
'#CC0000',
]
return fontColors[Math.floor(Math.random() * fontColors.length)]
}
function getRandomChar(){
const str ='ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890abcdefghijklmnopqrstuvwxyz'
return str[Math.floor(Math.random()*str.length)];
}
draw()
setInterval(draw,40)
</script>
</body>
</html>