您现在的位置是:网站首页> 编程资料编程资料
python 实现打印扫描效果详情_python_
2023-05-26
294人已围观
简介 python 实现打印扫描效果详情_python_

1. 介绍
前面我们尝试通过python实现了代码雨以及字母随机闪烁的效果,这次,我们再来实现一个代码的线性扫面。
同样的,此次我们仍然是使用30行代码来实现这个效果。
此次我们只是用pygame与random两个包,首先,将他们导入:
import pygame import random
之后,我们进行pygame界面的初始化工作:
# 参数 SCREENSIZE=(600,600) BLACK=(0,0,0,13) # 初始化 pygame.init() font = pygame.font.SysFont('宋体', 20) screen = pygame.display.set_mode(SCREENSIZE) surface = pygame.Surface(SCREENSIZE, flags=pygame.SRCALPHA) pygame.Surface.convert(surface) surface.fill(BLACK) screen.fill(BLACK)之后设置一下我们字体的相关内容:
# 内容 lib=[chr(i) for i in range(48,48+10)] + [chr(i) for i in range(97,97+26)] # [0-9 a-z] texts = [font.render(l, True, (0, 255, 0)) for l in lib] cols = list(range(40)) # 字体15, 窗口600
最后在一个循环中,更新界面并绘制出代码雨:
while True: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() pygame.time.delay(33) screen.blit(surface, (0, 0)) for i in range(n:=len(cols)): text = random.choice(texts) # 字母扫描 screen.blit(text, (i * 15, cols[i] * 15)) cols[i] = (cols[i]+1)%40 pygame.display.flip()
2. 完整代码
完整代码如下:
import pygame import random # 参数 SCREENSIZE=(600,600) BLACK=(0,0,0,13) # 初始化 pygame.init() font = pygame.font.SysFont('宋体', 20) screen = pygame.display.set_mode(SCREENSIZE) surface = pygame.Surface(SCREENSIZE, flags=pygame.SRCALPHA) pygame.Surface.convert(surface) surface.fill(BLACK) screen.fill(BLACK) # 内容 lib=[chr(i) for i in range(48,48+10)] + [chr(i) for i in range(97,97+26)] # [0-9 a-z] texts = [font.render(l, True, (0, 255, 0)) for l in lib] cols = list(range(40)) # 字体15, 窗口600 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() pygame.time.delay(33) screen.blit(surface, (0, 0)) for i in range(n:=len(cols)): text = random.choice(texts) # 字母扫描 screen.blit(text, (i * 15, cols[i] * 15)) cols[i] = (cols[i]+1)%40 pygame.display.flip()截止到现在,我们已经学会了用简简单单的30行代码实现代码雨,闪烁代码以及线性扫描三种炫酷的特效了,相信大家在这个过程中也对 python 有了一个最初步的理解与认识,
到此这篇关于python 实现打印扫描效果详情的文章就介绍到这了,更多相关python 打印扫描内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
您可能感兴趣的文章:
相关内容
- 如何在Python中利用matplotlib.pyplot画出函数图详解_python_
- 使用Python matplotlib绘制简单的柱形图、折线图和直线图_python_
- OpenCV实现相机标定_python_
- Python Celery定时任务详细讲解_python_
- Python办公自动化SFTP详解_python_
- Python利用matplotlib.pyplot.boxplot()绘制箱型图实例代码_python_
- opencv实现矿石图片检测矿石数量_python_
- Python实现多项式拟合正弦函数详情_python_
- Python调整matplotlib图片大小的3种方法汇总_python_
- Python文件相关操作和方法汇总大全_python_
