Introduction:

Every time I go home xiaobian side will gather a bunch of children, this is the benefit of living in a village.

A home to receive the cordial greetings of seven aunts and eight aunts, the relationship is particularly good, the children are not afraid of me.

Last year, there were a lot of crying at the disaster site because some gifts for children were not distributed evenly……

What does my mom think I did to them?

Emmmmmm, I just want to say, “Excuse me.”

This year’s Mid-Autumn Festival is afraid of the children at home because of the distribution of gifts to repeat the same mistake, I made a Mid-Autumn Festival gift scratch-off, scratch what you take!


The body of the

The gifts for children in the Mid-Autumn Festival have been selected. The pictures are as follows:

A pile of Mid-Autumn moon cake plush doll ~ should also spread.

Read a random picture:

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)
Copy the code

Main function:

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 (' mid Autumn Moon cake stuffed figure -- #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()Copy the code

Effect:

Attached with the full source:

"' theme: Import OS import sys import random Import PyGame BGMPATH = 'music/ GM.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 (' mid Autumn Moon cake stuffed figure -- #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()Copy the code

conclusion

All right! That’s all for the article! If you need a complete package of source code + material remember the old place.

Source base group: [private letter xiaobian 06] can be free oh!!

Your support and praise is my biggest motivation, remember the three lian oh ~