This article is participating in Python Theme Month. See the link for details

Pygame is a powerful and fun set of modules for managing graphics, animation, and even sound, making it easy to develop complex games. By using Pygame to handle tasks such as drawing images on the screen, you don’t have to worry about a lot of tedious and difficult coding, but instead focus on the high-level logic of your program.

Today is the realization of this point screen, flower color waves of small games

Gameplay: Every time you click the mouse, you will take the mouse as the center of the circle, and continue to expand the circle outward (similar to the diffusion of water waves), so as to form a concentric circle, and reach a random size and stop expanding. The color of each of these concentric circles is random.

Initialize the

import pygame, random, sys, time pygame.init() screen = pygame.display.set_mode([600, 400]) screen.fill((255, 255, 255)) radiusr = 0 ArrRadiusr = [0] * 10 # Radius of the circle ARRAddRadiusr = [0] * 10 # Radius increment of the circle ARRRadiusbool = [False] * 10 # Whether the circle exists False indicates that the circle under this index does not exist, True indicates the presence of arrRadiusx = [0] * 10 # Coordinates of the circle x axis ArrRadiusy = [0] * 10 # Coordinates of the circle Y axis RGBx = [0] * 10 # Color RGB value the first value RGBy = [0] * 10 # RGBz = [0] * 10 # RGBz = [0] * 10Copy the code

Initialization of a variable. Let’s start with the initial values for the key variables

The core logic

While True: time.sleep(0.1) # 0.1 SEC for event in PyGame.event.get (): # listener if event.type == PyGame.mouseButtonDown: Arrradiusbool [num] = True # Set arrradiusr[num] = 0 RGBx[num] = random. Randint (0, arrradiusx[num] = pygame.mouse.get_pos() RGBz[num] = random. Randint (0, 255) RGBz[num] = random. Randint (0, 255) Pygame.draw. Circle (screen, pygame.color (RGBx[num], RGBy[num], RGBz[num]), arrradiusy[num]), arrradiusr[num], 1) if event.type == pygame.QUIT: pygame.quit() sys.exit() for i in range(10): Pass else: if (arrRadiusbool [I] < random.randint(10, 50)): if (arrRadiusbool [I] < random.randint(10, 50)) Arrradiusr [I] += arrAddRadiusr [I] pygame.draw.circle(screen, Pygame.color (RGBx[I], RGBy[I], RGBz[I]), arrRadiusx [I], arrRadiusy [I]), arrRadiusr [I], 1) else: Pygame.display.update () arrRadiusbool [I] = False # If the circle has reached its maximum, this sets the index value of the circle to non-existent pygame.display.update()Copy the code

The core logic is mainly to do a random color, circular drawing concentric circles.

If event.type == PyGame. MOUSEBUTTONDOWN: # mouse down. This is the mouse event trigger, need to learn.

Overall, getting started is not difficult and easy to learn. The above idea is quite clear. For more complete game source code, please go to the public number: poetic code. Now that we’re in. Just give me a “like” and leave.