使用canvas+js实现黑客帝国代码雨效果
html代码:
<canvas width="1272" height="275"></canvas>
js代码:
let canvas = document.querySelector('canvas'); let ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; let str = "hjyl.org".split(''); let arr = Array(Math.ceil(canvas.width / 10)).fill(0); let run = () => { ctx.fillStyle = 'rgba(0,0,0,0.05)'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = '#0f0'; arr.forEach((item, index) => { 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; }); }; // run() setInterval(run, 40);
声明:本文采用 BY-NC-SA 协议进行授权,如无注明均为原创,转载请注明转自 你好!刘
本文地址:canvas+js 实现黑客帝国代码雨效果
本文地址:canvas+js 实现黑客帝国代码雨效果
发表评论