导语
每次回家小编的身边都会聚集着一堆小朋友,这就是家住一个村的好处。
一回家就接收到七大姑八大姨的亲切的问候,关系那是特别不错的,小朋友也不怕我。
去年因为给小朋友带了一些礼物但是分配不均匀,导致了灾难现场哭声一片......
我老妈还以为我咋的她们了?
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 刮刮卡内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/weixin_55822277/article/details/120235781