首页 > 其他分享 >pygame写一个黑客帝国屏保

pygame写一个黑客帝国屏保

时间:2024-10-12 10:14:42浏览次数:6  
标签:neirong filelines 屏保 黑客帝国 pygame file path font

代码:

#coding=utf-8

import os,sys,re,time
import pygame
import random
from win32api import GetSystemMetrics
from tkinter import messagebox

#pyinstaller -F -w pygame_heike.py

pygame.init()
pygame.display.set_caption("黑客帝国屏幕保护")

percent = 1
screen_width = GetSystemMetrics(0)
screen_height = GetSystemMetrics(1)
window_width = int(screen_width*percent)
window_height = int(screen_height*percent)

dt = 0
clock = pygame.time.Clock()

screen = pygame.display.set_mode((window_width, window_height))

#停止处理输入法事件
pygame.key.stop_text_input()

font_path = os.path.join(os.path.dirname(sys.argv[0]), 'simsun.ttc')
fonts = []
fontSizes = []
fontLineStarts = []
fontSpends = []
for i in range(0, 500):
    font_size = int((500-i)*0.03)
    font = pygame.font.Font(font_path, font_size)
    
    fontSizes.append(font_size)
    fontLineStarts.append(0)
    fontSpends.append(random.randint(1,7))
    fonts.append(font)
    
def read_directory(path):
    resfiles = []
    for root, dirs, files in os.walk(path):
        for file in files:
            if not file.endswith(".php"):
                continue
            full_path = os.path.join(root, file)
            full_path = full_path.replace("\\", "/")
            (linenum, neirong) = read_file(full_path)
            if linenum > 500:
                resfiles.append(neirong)
    
    #print(resfiles)
    #sys.exit(0)
    return resfiles
            
def read_file(path):
    file = open(path, 'r', encoding='utf-8')
    neirong = file.read()
    file.close()
    
    filelines = [i for i in neirong.split("\n") if i.strip()]
    linenum = len(filelines)
    neirong = "\n".join(filelines)
    
    return linenum, neirong


neirongs = read_directory("D:/workspace/workspace_company/oldoa-test/vendor")
neirong = neirongs[random.randint(0, len(neirongs)-1)]
#print(neirong)
#sys.exit(0)

maxline = 100
filelines = [i for i in neirong.split("\n")]
start = random.randint(0, len(filelines)-16)
lines = filelines[start:start+maxline]

runNum = 0
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            
    keys_pressed = pygame.key.get_pressed()
    
    #ESC键
    if keys_pressed[pygame.K_ESCAPE]:
        running = False
        
    if runNum % 200 == 0:
        pass
        #start = random.randint(0, len(filelines)-16)
        #lines = filelines[start:]
        
    screen.fill("black")
    
    for i,line in enumerate(lines):
        fields = [f for f in line]
        starty = int(fontLineStarts[i])
        fontLineStarts[i] -= fontSpends[i]*dt

        if starty < 0:
            starty = len(fields)-1
        
        if fontLineStarts[i] < 0:
            fontLineStarts[i] = len(fields)-1
        
        fields = fields[starty:] + fields[:starty]
        
        r = 0
        g = 70
        b = 0
        for j,field in enumerate(fields):
            color = (r, g, b)
            font = fonts[j]
            font_size = fontSizes[j]
            rect_text = font.render(field, 1, color)
            screen.blit(rect_text, (i*font_size*2, j*font_size))
            r += 1
            g += 2
            b += 3
            
            if r > 255:
                r = 0
            if g > 255:
                g = 0
            if b > 255:
                b = 0
                
    runNum += 1
        
    #更新显示
    pygame.display.flip()
    #pygame.display.update()
    
    dt = clock.tick(60) / 600
    
pygame.quit()

  

效果:

 

pyinstaller -F -w pygame_heike.py

先将代码编译成exe,然后将exe后缀的程序改成scr(pygame_heike.exe->pygame_heike.scr)

再将文件pygame_heike.scr 和字体文件 复制到C:\Windows\System32下

鼠标移到桌面,右击,选择个性化,屏幕保护程序,选择pygame_heike。

 

标签:neirong,filelines,屏保,黑客帝国,pygame,file,path,font
From: https://www.cnblogs.com/xuxiaobo/p/18459957

相关文章

  • 在VS2022上安装pygame模块
    一、安装在vs2022中随便打开或生产一个python项目,找到最右边的“解决方案资源管理器”,并找到“python环境”,点击鼠标右键打开“查看所有python环境”打开以后找到下面的“在PowerShell中打开”,点击打开然后输入”pipinstallpygame“并等待安装即可二、测试输入以下代码并运......
  • 如何使用 pygame.image.load() 加载图像?
    我只是想知道语法。如何使用pygame.image.load()加载图像?举个例子,我想加载一个名为cat.png的图像-并输入这个pygame.image.load('cat.png')那么,图像cat.png应该保存在哪里?当然可以,让我们来分解一下如何使用Pygame加载图像。1.导入和初始化首先,你......
  • 抖音怎么录屏保存?网页录屏和直播内容录制屏幕工具软件推荐
    在数字化时代,直播已成为我们获取信息和娱乐的重要方式。无论是抖音上的热门直播,还是其他平台的精彩内容,我们都希望能够随时回顾这些瞬间。然而,直播的即时性意味着一旦错过,就可能再也看不到了。幸运的是,有多种录屏软件可以帮助我们捕捉并保存这些珍贵的时刻。以下是几款适合录制......
  • Android 10.0 mtk平板camera2横屏预览旋转90度横屏保存录像旋转90度功能实现
    1.前言在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,点击录像保存的视频依然是竖屏的,所以说同样需要将视频也保存为横屏视频了,所以就需......
  • Unity3d 截屏保存到相册,并且刷新相册
    要做一个截图的功能,并且玩家可以在相册中看到。 做的时候遇到了三个问题: 1、unity自带的截图API,Application.CaptureScreenshot在Android上不生效 2、图片保存的路径获取 3、保存的图片可以在手机的文件管理中找到,但是相册中没有。 解决......
  • pygame封装常用控件,第二日,有滑块的文本显示域
    #coding=utf-8importos,sys,re,timeimportpygameimportrandomfromwin32apiimportGetSystemMetricsfromtkinterimportmessageboxpygame.init()pygame.display.set_caption("我的控件")percent=0.6screen_width=GetSystemMetrics(0)screen_heig......
  • pygame封装连个常用控件
    #coding=utf-8importos,sys,re,timeimportpygameimportrandomfromwin32apiimportGetSystemMetricsfromtkinterimportmessageboxpygame.init()pygame.display.set_caption("我的控件")percent=0.6screen_width=GetSystemMetrics(0)screen_heig......
  • pygame手搓贪吃蛇
    代码:#coding=utf-8importos,sys,re,timeimportpygameimportrandomfromwin32apiimportGetSystemMetricsimportcopypygame.init()pygame.display.set_caption("贪吃蛇")percent=0.6screen_width=GetSystemMetrics(0)screen_height=GetSystemM......
  • pygame手搓五子棋
    代码:#coding=utf-8importos,sys,re,timeimportpygameimportrandomfromwin32apiimportGetSystemMetricspygame.init()pygame.display.set_caption("五子棋")percent=0.6screen_width=GetSystemMetrics(0)screen_height=GetSystemMetrics(1)wi......
  • pygame各类形状
    代码:#coding=utf-8importos,sys,re,time,mathimportpygameimportrandomfromwin32apiimportGetSystemMetricsfrommathimportpipygame.init()pygame.display.set_caption("各种形状测试")percent=0.6screen_width=GetSystemMetrics(0)screen_hei......