• 黑客帝国代码雨


    黑客帝国代码雨奉上,之前一直想写,但一直没抽出时间来,今天把他写了,也算了了装心事

    效果图如下
    在这里插入图片描述
    原理就不讲了,代码写的很清楚而且不长
    有不懂的评论区问我就好

    DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>canvas代码雨title>
      <style>
        * {
          padding: 0;
          margin: 0;
        }
    
        canvas {
          display: block;
          width: 100vw;
          height: 100vh;
          background-color: black;
        }
      style>
    head>
    
    <body>
      <canvas>canvas>
      <script>
        const canvas = document.querySelector('canvas');
        const ctx = canvas.getContext('2d');
        function init() {
          canvas.width = window.innerWidth * devicePixelRatio
          canvas.height = window.innerHeight * devicePixelRatio
        }
        init()
        const fontSize = 10 * devicePixelRatio
        ctx.font = fontSize + 'px Microsoft YaHei'
        const column = Math.floor(canvas.width / fontSize)
        const charIndex = new Array(column).fill(0)
        function draw() {
          ctx.fillStyle = 'rgba(0,0,0,0.1)'
          ctx.fillRect(0, 0, canvas.width, canvas.height)
          ctx.fillStyle = '#0f0'
          ctx.textBaseline = 'top'
          for (let i = 0; i < column; i++) {
            const text = getRandomChat()
            const x = i * fontSize
            const y = charIndex[i] * fontSize
            ctx.fillText(text, x, y)
            if (y > canvas.height && Math.random() > 0.99) {
              charIndex[i] = 0
            } else {
              charIndex[i]++
            }
          }
        }
        function getRandomChat() {
          const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
          return str.charAt(Math.floor(Math.random() * str.length))
        }
        draw()
        setInterval(draw, 30)
    
      script>
    body>
    
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
  • 相关阅读:
    Win环境安装Protobuf 2.0 版本
    CASIO虚线替换部分及切线支距法
    锐捷BGP基础配置
    C#基础入门教程-基本语法
    (七)CSharp-CSharp图解教程版-事件
    模拟用户登录功能的实现以及演示SQL注入现象
    STM32两种输入两种输出仿真设计合集
    独立站FP收款黑科技来啦!再也不用担心账户被封了~
    Python数据分析与可视化
    mysql数据库
  • 原文地址:https://blog.csdn.net/weixin_44368963/article/details/133656170