AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

病毒

作者: 作者的头像   钱泓谷 ,  2025-07-06 10:06:55 · 江苏 ,  所有人可见 ,  阅读 3


0


import pygame
import random
import math
import sys
import os
import time
from pygame import gfxdraw

# 初始化pygame
pygame.init()

# 获取屏幕尺寸
info = pygame.display.Info()
screen_width, screen_height = info.current_w, info.current_h
screen = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN)
pygame.display.set_caption("系统安全扫描")

# 隐藏鼠标
pygame.mouse.set_visible(False)

# 颜色定义
GREEN = (0, 255, 0)
RED = (255, 0, 0)
YELLOW = (255, 255, 0)
BLUE = (0, 120, 255)
PURPLE = (180, 0, 255)
BACKGROUND = (10, 10, 30)

# 矩阵风格字符
CHARS = "01abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%&*"

# 扫描线类
class ScanLine:
    def __init__(self):
        self.x = 0
        self.y = random.randint(0, screen_height)
        self.speed = random.randint(5, 15)
        self.length = random.randint(50, 200)
        self.color = (0, random.randint(200, 255), random.randint(50, 150))
        self.width = random.randint(1, 3)

    def move(self):
        self.x += self.speed
        if self.x > screen_width:
            self.x = 0
            self.y = random.randint(0, screen_height)

    def draw(self, surface):
        pygame.draw.line(surface, self.color, (self.x, self.y), (self.x + self.length, self.y), self.width)

# 矩阵雨滴类
class MatrixDrop:
    def __init__(self, x):
        self.x = x
        self.y = random.randint(-100, -10)
        self.speed = random.randint(5, 15)
        self.length = random.randint(5, 30)
        self.chars = []
        self.last_char_time = 0
        self.char_delay = random.randint(50, 200)

    def move(self):
        self.y += self.speed
        if self.y > screen_height:
            self.y = random.randint(-100, -10)
            self.length = random.randint(5, 30)

    def update_chars(self):
        current_time = pygame.time.get_ticks()
        if current_time - self.last_char_time > self.char_delay:
            self.chars.append({
                'char': random.choice(CHARS),
                'y': self.y,
                'brightness': 255
            })
            self.last_char_time = current_time

        # 更新现有字符
        for char in self.chars[:]:
            char['brightness'] -= 5
            if char['brightness'] <= 0:
                self.chars.remove(char)

    def draw(self, surface, font):
        for i, char_info in enumerate(self.chars):
            # 头部字符为绿色,其他为渐变色
            if i == len(self.chars) - 1:
                color = (0, 255, 0)
            else:
                fade = min(255, max(0, char_info['brightness']))
                color = (0, fade, 70)

            char_surface = font.render(char_info['char'], True, color)
            surface.blit(char_surface, (self.x, char_info['y']))

# 创建扫描线
scan_lines = [ScanLine() for _ in range(20)]

# 创建矩阵雨滴
matrix_drops = []
matrix_font = pygame.font.SysFont('Courier', 18, bold=True)
for i in range(screen_width // 15):
    matrix_drops.append(MatrixDrop(i * 15))

# 创建警告信息
warning_font = pygame.font.SysFont('Arial', 36, bold=True)
small_font = pygame.font.SysFont('Arial', 24)

# 主循环
clock = pygame.time.Clock()
start_time = time.time()

running = True
while running:
    current_time = time.time() - start_time

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type == pygame.KEYDOWN:
            # 只有特殊组合键才能退出
            if event.key == pygame.K_q and pygame.key.get_mods() & pygame.KMOD_CTRL and pygame.key.get_mods() & pygame.KMOD_ALT:
                running = False

    # 填充背景
    screen.fill(BACKGROUND)

    # 绘制扫描线
    for line in scan_lines:
        line.move()
        line.draw(screen)

    # 绘制矩阵雨
    for drop in matrix_drops:
        drop.move()
        drop.update_chars()
        drop.draw(screen, matrix_font)

    # 绘制扫描动画
    scan_y = (pygame.time.get_ticks() // 20) % screen_height
    pygame.draw.line(screen, (0, 200, 100, 150), (0, scan_y), (screen_width, scan_y), 3)

    # 绘制警告信息
    warning_text = warning_font.render("! 检测到系统漏洞 !", True, RED)
    screen.blit(warning_text, (screen_width//2 - warning_text.get_width()//2, 50))

    # 绘制进度条
    progress_width = min(screen_width * 0.8, screen_width * 0.8 * (current_time / 30))
    pygame.draw.rect(screen, (50, 50, 70), (screen_width*0.1, 150, screen_width*0.8, 30))
    pygame.draw.rect(screen, BLUE, (screen_width*0.1, 150, progress_width, 30))
    pygame.draw.rect(screen, (100, 100, 150), (screen_width*0.1, 150, screen_width*0.8, 30), 2)

    # 进度文本
    percent = min(100, int(current_time / 30 * 100))
    progress_text = small_font.render(f"系统扫描中: {percent}%", True, YELLOW)
    screen.blit(progress_text, (screen_width//2 - progress_text.get_width()//2, 155))

    # 绘制检测到的"威胁"
    threat_text = small_font.render("检测到的威胁:", True, YELLOW)
    screen.blit(threat_text, (screen_width*0.15, 200))

    threats = [
        "Trojan.Generic.123456 - 高风险",
        "Exploit.CVE20231234 - 严重风险",
        "PUP.Optional.Bundleware - 中等风险",
        "Riskware.BitCoinMiner - 高风险",
        "Adware.PopUnder.5678 - 低风险"
    ]

    for i, threat in enumerate(threats):
        threat_surface = small_font.render(threat, True, RED if i < 3 else YELLOW)
        screen.blit(threat_surface, (screen_width*0.2, 240 + i*35))

    # 绘制系统信息
    sys_text = small_font.render(f"内存使用: {random.randint(75, 95)}% | CPU负载: {random.randint(80, 99)}% | 温度: {random.randint(65, 85)}°C", 
                               True, (200, 200, 200))
    screen.blit(sys_text, (screen_width//2 - sys_text.get_width()//2, screen_height - 100))

    # 绘制退出提示
    exit_text = small_font.render("按 Ctrl+Alt+Q 退出诊断", True, (150, 150, 150))
    screen.blit(exit_text, (screen_width//2 - exit_text.get_width()//2, screen_height - 50))

    # 绘制扫描效果
    for _ in range(20):
        x = random.randint(0, screen_width)
        y = random.randint(0, screen_height)
        pygame.draw.circle(screen, (0, 150, 100, 50), (x, y), 2)

    pygame.display.flip()
    clock.tick(30)
pygame.quit()
sys.exit()

1 评论


用户头像
钱泓谷   2025-07-06 10:07 · 江苏         踩      回复

用的是Python


App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息