index.html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>code rain</title>
</head>
<style>
*{
padding:0;
margin:0;
overflow: hidden;
}
</style>
<body>
<canvas id="canvas"></canvas>
<script src="index.js" ></script>
</body>
</html>
typescript 代码:
/*-代码雨*/
// @ts-ignore
let canvas:HTMLCanvasElement = document.getElementById('canvas')
let ctx = canvas.getContext('2d')
canvas.width = screen.availWidth
canvas.height = screen.availHeight
let str:string[] = 'BlueSpot.json'.split('')
let arr = Array(Math.ceil(canvas.width / 10) ).fill(0)
let rain = ():void =>{
// @ts-ignore
ctx.fillStyle = 'rgba(0,0,0,.05)'
// @ts-ignore
ctx.fillRect(0,0,canvas.width,canvas.height)
// @ts-ignore
ctx.fillStyle = '#0f0'
arr.forEach((item,index)=>{
// @ts-ignore
ctx.fillText( str[Math.floor(Math.random() * str.length)] ,index * 10 ,item + 10 )
arr[index] = item > canvas.height || item > 10000* Math.random() ? 0 : item + 10
})
}
setInterval(rain,40)
console.log(canvas,arr)