博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
html5实现黑客帝国数字矩阵效果
阅读量:7074 次
发布时间:2019-06-28

本文共 2112 字,大约阅读时间需要 7 分钟。

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Martrix</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: #000;
            overflow: hidden;
            color:#e6922a;
        }
    </style>
</head>
<body>
    <canvas id="canvas"></canvas>
    
    <script type="text/javascript">
        var canvas = document.getElementById("canvas"),
            context = canvas.getContext("2d");
        var fontSize = 14,
            listText = "0123456789ABCDEF".split(""),
            column, row,
            listColumn = [];
        function draw() {
            //画背景
            context.fillStyle = "rgba(0, 0, 0, 0.05)";
            context.fillRect(0, 0, canvas.width, canvas.height);
            context.save();
            //画Logo
            context.shadowColor = "#074425";
            context.shadowBlur = parseInt(Math.random() * 40 + 1);
            context.font = "bold 36px Arial";
            context.fillStyle = "#eefbf5";
            context.fillText("MARTRIX", (canvas.width / 2 - context.measureText("MARTRIX").width / 2), canvas.height - 200);
            context.fillText("REVOLUTIONS", (canvas.width / 2 - context.measureText("REVOLUTIONS").width / 2), canvas.height - 150);
            context.font = "16px Microsoft Yahei";
            context.fillText("HACK MATRIX MADE BY XH", (canvas.width / 2 - context.measureText("HACK MATRIX MADE BY XH").width / 2), canvas.height - 100);
            //画代码
            context.restore();
            context.font = "normal " + fontSize + "px Arial";
            context.fillStyle = "#12ee46";
            for (var i = 0; i < column; i++) {
                if (Math.random() > 0.5) {
                    var str = listText[parseInt(Math.random() * listText.length)];
                    context.fillText(str, i * fontSize, listColumn[i] * fontSize);
                    listColumn[i] += 1;
                    if (listColumn[i] >= row) {
                        listColumn[i] = 0;
                    }
                }
            }
        }
        function resize() {
            canvas.width = window.innerWidth - 3;
            canvas.height = window.innerHeight - 3;
            column = canvas.width / fontSize,
            row = canvas.height / fontSize;
            for (var i = 0; i < column; i++) {
                listColumn[i] = 1;
            }
        }
        window.addEventListener("resize", resize);
        canvas.addEventListener("mousedown", function () {
            clearInterval(timer);
            timer = setInterval(draw, 20);
        });
        canvas.addEventListener("mouseup", function () {
            clearInterval(timer);
            timer = setInterval(draw, 40);
        });
        resize();
        var timer = setInterval(draw, 40);
    </script>
</body>

</html>

转载地址:http://cluml.baihongyu.com/

你可能感兴趣的文章
Odoo 二次开发教程(五)-新API的介绍与应用
查看>>
VC++ 一个简单的Log类
查看>>
Java内存模型深度解析:重排序 --转
查看>>
CentOS防火墙iptables的配置方法详解
查看>>
webpack搭建前端一条龙服务
查看>>
1.ASP.NET MVC使用EPPlus,导出数据到Excel中
查看>>
nxn随机矩阵乘以概率向量依旧是概率向量
查看>>
【转载】TCP协议要点和难点全解
查看>>
mysql修改表、字段、库的字符集
查看>>
realm vs. domain
查看>>
关闭Spring Boot的Jsckson的FAIL_ON_EMPTY_BEANS
查看>>
Oracle 切割字符查询
查看>>
结构体内存对齐具体解释
查看>>
Cocos Code IDE里xcodeprojectlua脚本更新
查看>>
LEARN SWIFT
查看>>
jenkins指定具体项目具体分支进行构建部署
查看>>
关于音频文件的上传
查看>>
powershell入门教程-v0.3版
查看>>
nginx的proxy_cache缓存配置
查看>>
论文笔记:Variational Capsules for Image Analysis and Synthesis
查看>>