https://blog.csdn.net/Feng_wwf/article/details/108461313
玩了一下,好像实现了每一行都是完整的话,造成一种密文的效果hhh。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Code</title>
<style>
body{
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id="myCanvas"></canvas>
<script>
const width = document.getElementById("myCanvas").width = screen.availWidth;
const height = document.getElementById("myCanvas").height = screen.availHeight;
const ctx = document.getElementById("myCanvas").getContext("2d");
const arr = Array(Math.ceil(width / 10)).fill(0);
const str = "$%@#$%$@#%$#@%#@$%$@#%$#@!%^!%#^%$!关键字#@$#@$#@!$!#@$#@!^$$$#@$#@!$!#@$#@!$".split("");
function rain() {
ctx.fillStyle = "rgba(0,0,0,0.05)";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = "#8FA";
arr.forEach(function (value, index) {
//Math.floor(Math.random() * str.length)]
ctx.fillText(str[(index + value)%str.length], index * 10, value + 10);
arr[index] = value >= height || value > 168888 * Math.random() ? 0 : value + 12;
});
}
setInterval(rain, 30);
</script>
</body>
</html>