这是用pygame开发的一个手电筒探照黑夜类型的程序。本程序有turtle版,和turtle版不同的时,这个程序的手电筒是能缩放的。
以下是代码预览:
"""
手电筒探照程序,每像素演示,本程序以图为底,以另一个surface为遮罩层。
让这个遮罩层随着鼠标的移动而移动,按滚动上或下能放大或缩小‘遮罩层’。
"""
__author__ = '李兴球'
__date__ = '2019/10/13'
__blog__ = 'www.lixingqiu.com'
import pygame
from pygame.locals import *
pygame.init()
image = '印度姑娘.jpg'
image = pygame.image.load(image)
width,height = image.get_size()
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("pygame手电筒探照程序之印度姑娘by李兴球")
................
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:running=False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 5 :
radius = radius + 4
radius = min(radius,200)
elif event.button == 4:
radius = radius - 4
radius = max(4,radius)
........................
pygame.display.update()
mask_image = mask_image2.copy() # 还原
pygame.quit()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

