⿊客帝国的代码⾬在桌⾯新建⼀个.txt⽂件,把下⾯代码放进去,再把后缀名改成.html,双击打开就好了
<!DOCTYPE html>
<html>
<head>
<title>⿊客帝国</title>
</head>
<body><canvas id="canvas"></canvas>
<style type="text/css">
body {
margin:0;
padding:0;
overflow: hidden;
}
</style>
<script type="text/javascript">
var canvas = ElementById('canvas');
var ctx = Context('2d');
html代码转链接canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
var texts ='156dsfcac'.split('');
var fontSize =16;
var columns = canvas.width / fontSize;
/
/ ⽤于计算输出⽂字时坐标,所以长度即为列数
var drops =[];
//初始值
for(var x =0; x < columns; x++){
drops[x]=1;
}
function draw(){
//让背景逐渐由透明到不透明
ctx.fillStyle ='rgba(0, 0, 0, 0.05)';
ctx.fillRect(0,0, canvas.width, canvas.height);
//⽂字颜⾊
ctx.fillStyle ='#0F0';
ctx.font = fontSize +'px arial';
//逐⾏输出⽂字
for(var i =0; i < drops.length; i++){
var text = texts[Math.floor(Math.random()* texts.length)];
ctx.fillText(text, i * fontSize, drops[i]* fontSize);
if(drops[i]* fontSize > canvas.height || Math.random()>0.95){
drops[i]=0;
}
drops[i]++;
}
}
setInterval(draw,33);
</script>
</body>
</html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。