用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

陨落之弓    -  云代码空间

——

黑客帝国流星雨

2020-05-31|1088阅||

摘要:<!DOCTYPE html> <html> <head>     <title>黑客帝国代码雨</title> </head>   <body> <canvas id="canvas"&g

<!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 = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');
 
 
    canvas.height = window.innerHeight;
    canvas.width = window.innerWidth;
 
    var texts = '0123456789'.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>

顶 15踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: 陨落之弓
    • 等级: 中级程序员
    • 积分: 115
    • 代码: 6 个
    • 文章: 5 篇
    • 随想: 0 条
    • 访问: 5 次
    • 关注

    标签

    最新提问

      站长推荐