欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

中秋送禮分配不均這款python刮刮卡完美解決問題

 更新時間:2021年09月18日 16:19:02   作者:顧木子吖  
這篇文章主要介紹了用Python實現(xiàn)一個抽獎刮刮卡來解決給小朋友的禮物不均,文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以了解下

導語

每次回家小編的身邊都會聚集著一堆小朋友,這就是家住一個村的好處。

一回家就接收到七大姑八大姨的親切的問候,關系那是特別不錯的,小朋友也不怕我。

圖片

去年因為給小朋友帶了一些禮物但是分配不均勻,導致了災難現(xiàn)場哭聲一片......

我老媽還以為我咋的她們了?

圖片

emmmmmm,完了我只想說一句,“打擾了”

今年中秋怕家里的小孩子們因為分配禮物重蹈覆轍,聰明的我制作了一款中秋禮物刮刮樂,刮到什么就拿什么!

正文

中秋送給孩子們的禮物已經(jīng)選好了,當當當圖片如下:

一堆中秋月餅的毛絨公仔玩偶~應該還行撒。

隨機讀取一張圖片:

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)

主函數(shù):

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 刮刮卡內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論