Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to make scratch card to solve the uneven distribution of moon cakes

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you how to use python to make scratch cards to solve the uneven distribution of mooncakes, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Text

The gifts for the children during the Mid-Autumn Festival have been chosen. Dangdang pictures are as follows:

A bunch of plush dolls of Mid-Autumn Festival moon cakes ~ should still be scattered.

Read a picture at random:

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)

Main function:

Def main (): pygame.init () pygame.mixer.init () pygame.mixer.music.load (BGMPATH) pygame.mixer.music.play (- 1 0) pygame.mouse.set_cursor (* pygame.cursors.diamond) screen = pygame.display.set_mode (SCREENSIZE) pygame.display.set_caption ('Mid-Autumn Festival plush doll-source base: # 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 ()

Effect picture:

Attached code:

Theme: python gifts for a bunch of children coming home for the Mid-Autumn Festival import osimport sysimport randomimport pygame BGMPATH = 'music/bgm.mp3'IMAGEDIR =' pictures'SUPPORTEXTS = ['jpg',' png', 'bmp'] SCREENSIZE = (800,600) WHITE = (255,255,255,27) GRAY = (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) pygame.mouse.set_cursor (* pygame.cursors.diamond) screen = pygame.display.set_mode (SCREENSIZE) pygame.display.set_caption ('Mid-Autumn Festival plush doll-source base: # 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 () the above is how to use python to make scratch cards to solve the uneven distribution of mooncakes Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report