中秋送礼分配不均这款python刮刮卡完美解决问题

2022-07-21,,,

导语

每次回家小编的身边都会聚集着一堆小朋友,这就是家住一个村的好处。

一回家就接收到七大姑八大姨的亲切的问候,关系那是特别不错的,小朋友也不怕我。

去年因为给小朋友带了一些礼物但是分配不均匀,导致了灾难现场哭声一片......

我老妈还以为我咋的她们了?

emmmmmm,完了我只想说一句,“打扰了”

今年中秋怕家里的小孩子们因为分配礼物重蹈覆辙,聪明的我制作了一款中秋礼物刮刮乐,刮到什么就拿什么!

正文

中秋送给孩子们的礼物已经选好了,当当当图片如下:

一堆中秋月饼的毛绒公仔玩偶~应该还行撒。

随机读取一张图片:

def readimagerandomly():
	filenames = os.listdir(imagedir)
	filenames = [f for f in filenames if f.split('.')[-1] in supportexts]
	imgpath = os.path.join(imagedir, random.choice(filenames))
	return pygame.transform.scale(pygame.image.load(imgpath), screensize)

主函数:

def main():
	pygame.init()
	pygame.mixer.init()
	pygame.mixer.music.load(bgmpath)
	pygame.mixer.music.play(-1, 0.0)
	pygame.mouse.set_cursor(*pygame.cursors.diamond)
	screen = pygame.display.set_mode(screensize)
	pygame.display.set_caption('中秋月饼毛绒公仔—源码基地:#959755565#')
	surface = pygame.surface(screensize).convert_alpha()
	surface.fill(gray)
	image_used = readimagerandomly()
	while true:
		for event in pygame.event.get():
			if event.type == pygame.quit:
				pygame.quit()
				sys.exit(-1)
		mouse_event_flags = pygame.mouse.get_pressed()
		if mouse_event_flags[0]:
			pygame.draw.circle(surface, white, pygame.mouse.get_pos(), 40)
		elif mouse_event_flags[-1]:
			surface.fill(gray)
			image_used = readimagerandomly()
		screen.blit(image_used, (0, 0))
		screen.blit(surface, (0, 0))
		pygame.display.update()

效果图:

附代码:

'''
主题:
python中秋回家送一堆孩子的礼物
'''
import os
import sys
import random
import pygame
 
 
bgmpath = 'music/bgm.mp3'
imagedir = 'pictures'
supportexts = ['jpg', 'png', 'bmp']
screensize = (800, 600)
white = (255, 255, 255, 27)
gray = (192, 192, 192)
 
 
def readimagerandomly():
	filenames = os.listdir(imagedir)
	filenames = [f for f in filenames if f.split('.')[-1] in supportexts]
	imgpath = os.path.join(imagedir, random.choice(filenames))
	return pygame.transform.scale(pygame.image.load(imgpath), screensize)
 
 
def main():
	pygame.init()
	pygame.mixer.init()
	pygame.mixer.music.load(bgmpath)
	pygame.mixer.music.play(-1, 0.0)
	pygame.mouse.set_cursor(*pygame.cursors.diamond)
	screen = pygame.display.set_mode(screensize)
	pygame.display.set_caption('中秋月饼毛绒公仔—源码基地:#959755565#')
	surface = pygame.surface(screensize).convert_alpha()
	surface.fill(gray)
	image_used = readimagerandomly()
	while true:
		for event in pygame.event.get():
			if event.type == pygame.quit:
				pygame.quit()
				sys.exit(-1)
		mouse_event_flags = pygame.mouse.get_pressed()
		if mouse_event_flags[0]:
			pygame.draw.circle(surface, white, pygame.mouse.get_pos(), 40)
		elif mouse_event_flags[-1]:
			surface.fill(gray)
			image_used = readimagerandomly()
		screen.blit(image_used, (0, 0))
		screen.blit(surface, (0, 0))
		pygame.display.update()
 
 
'''run'''
if __name__ == '__main__':
	main()

​总结

好了!文章就到这里了哈!

到此这篇关于中秋送礼分配不均这款python刮刮卡完美解决问题的文章就介绍到这了,更多相关python 刮刮卡内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

《中秋送礼分配不均这款python刮刮卡完美解决问题.doc》

下载本文的Word格式文档,以方便收藏与打印。