中秋送禮分配不均這款python刮刮卡完美解決問題
導(dǎo)語
每次回家小編的身邊都會(huì)聚集著一堆小朋友,這就是家住一個(gè)村的好處。
一回家就接收到七大姑八大姨的親切的問候,關(guān)系那是特別不錯(cuò)的,小朋友也不怕我。
去年因?yàn)榻o小朋友帶了一些禮物但是分配不均勻,導(dǎo)致了災(zāi)難現(xiàn)場(chǎng)哭聲一片......
我老媽還以為我咋的她們了?
emmmmmm,完了我只想說一句,“打擾了”
今年中秋怕家里的小孩子們因?yàn)榉峙涠Y物重蹈覆轍,聰明的我制作了一款中秋禮物刮刮樂,刮到什么就拿什么!
正文
中秋送給孩子們的禮物已經(jīng)選好了,當(dāng)當(dāng)當(dāng)圖片如下:

一堆中秋月餅的毛絨公仔玩偶~應(yīng)該還行撒。
隨機(jī)讀取一張圖片:
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()
總結(jié)
好了!文章就到這里了哈!

到此這篇關(guān)于中秋送禮分配不均這款python刮刮卡完美解決問題的文章就介紹到這了,更多相關(guān)python 刮刮卡內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信