两款黑客代码雨效果

是不是看过黑客坐在电脑面前,疯狂敲键盘,屏幕面前疯狂输出一堆数字闪现而过,非常炫酷,没错,你也可以,下面分享两款代码雨。

图片[1]-两款黑客代码雨效果-聆风小站

第一款Python

首先安装依赖库:pygame,打开cmd,输入以下代码回车。

pip install pygame

代码如下:

import random
import pygame
pygame.init()
screenInfo = pygame.display.Info()
PANEL_width = screenInfo.current_w
PANEL_highly = screenInfo.current_h
FONT_PX = 15
winSur = pygame.display.set_mode((PANEL_width, PANEL_highly))  # 全屏模式
font = pygame.font.SysFont("arial", 20)
bg_suface = pygame.Surface((PANEL_width, PANEL_highly), flags=pygame.SRCALPHA)
pygame.Surface.convert(bg_suface)
bg_suface.fill(pygame.Color(0, 0, 0, 28))
winSur.fill((0, 0, 0))
letter = ["0", "1"]
texts = [font.render(str(letter[i]), True, (0, 255, 0))
         for i in range(len(letter))]
column = int(PANEL_width / FONT_PX)
drops = [0 for i in range(column)]
while True:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:  # 按esc键退出
            pygame.quit()
 
    pygame.time.delay(30)
    winSur.blit(bg_suface, (0, 0))
    for i in range(len(drops)):
        text = random.choice(texts)
        winSur.blit(text, (i * FONT_PX, drops[i] * FONT_PX))
        drops[i] += 1
        if drops[i] * 10 > PANEL_highly or random.random() > 0.95:
            drops[i] = 0
    pygame.display.flip()

 letter=[“自定义0”, “自定义1”, “自定义2”]

第二款html

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>MGT-404</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      body {
        background: black;
      }
      canvas {
        display: block;
      }
    </style>
  </head>
  <body>
    <canvas id="ad"></canvas>
    <script>
      var ad = document.getElementById("ad");
      var ctx = ad.getContext("2d");
      ad.height = window.innerHeight;
      ad.width = window.innerWidth;
      var chinese = "MGT";
      chinese = chinese.split("");
      var font_size = 10;
      var columns = ad.width / font_size;
      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, ad.width, ad.height);
        ctx.fillStyle = "#0F0";
        ctx.font = font_size + "px arial";
        for (var i = 0; i < drops.length; i++) {
          var text = chinese[Math.floor(Math.random() * chinese.length)];
          ctx.fillText(text, i * font_size, drops[i] * font_size);
          if (drops[i] * font_size > ad.height && Math.random() > 0.975)
            drops[i] = 0;
          drops[i]++;
        }
      }
      setInterval(draw, 50);
    </script>
  </body>
</html>

var chinese = “你想改的文字”


—— 本页内容已结束,喜欢请分享 ——
© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容