zoukankan      html  css  js  c++  java
  • 黑客帝国雨效果JS

    黑客帝国雨效果JS。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
        *{margin: 0;padding: 0;}
        body{overflow: hidden;}
        canvas{background: #111;}
        </style>
    </head>
    <body>
        <canvas id="canvas"></canvas>
        <script>
            var canvas = document.getElementById("canvas");
            var context = canvas.getContext("2d");
    
            var W = window.innerWidth;
            var H = window.innerHeight;
    
            canvas.width = W;
            canvas.height = H;
    
            var fontSize = 16;
            //计算列
            var colunm = Math.floor(W/fontSize);
            //console.log(colunm);
            //存储Y值
            var drops = [];
    
            for(var i = 0;i<colunm;i++){
                drops[i] = 1;
            }
            //console.log(...drops)
            var str = "Welcome JavaScript";
    
            //let tempRandom = Math.random()*str.length;
            //console.log(tempRandom,Math.floor(tempRandom))
            //把文字画到屏幕上
            function draw(){
                context.fillStyle = "rgba(0,0,0,0.05)";//文字随机出现的背景
                context.fillRect( 0, 0, W, H);
                context.font = "700 " + fontSize + "px ARIAL";
                context.fillStyle = "#00cc33";
                //context.fillStyle = randColor();
                //console.log("你好");
                for(var i = 0; i<colunm; i++){
                    //让字符串中的内容随机出现
                    var index = Math.floor(Math.random()*str.length);
                    var x = i*fontSize;
                    var y = drops[i]*fontSize;
                    context.fillText(str[index],x,y);
                    console.log(str[index],x,y);
                    if(y>=canvas.height && Math.random()>0.99){
                        drops[i] = 0;
                    }
                drops[i]++;
                }
            }
    
            function randColor(){
                var r = Math.floor(Math.random()*256);
                var g = Math.floor(Math.random()*256);
                var b = Math.floor(Math.random()*256);
                return "rgb("+r+","+g+","+b+")";
            }
    
            draw();
            setInterval(draw,20);
        </script>
    </body>
    </html>

    效果截图:

  • 相关阅读:
    GIT(分布式版本控制系统)
    mysql入门
    百度云上传下载会出现乱码,和丢失数据,.h,.so都会出现,暂未发现丢包现象
    qte搭建
    移植tslib
    网页移植前的问题(包括触摸屏)
    网页移植开发板
    开发板boa移植
    dump工具下,资料的备份与还原
    python-时间模块
  • 原文地址:https://www.cnblogs.com/liubeimeng/p/10618388.html
Copyright © 2011-2022 走看看