Game Development 4 min read

Create Expanding Ripple Effects with Pygame: A Step-by-Step Guide

This tutorial explains how to use Python's Pygame library to generate random-colored, expanding ripple circles that originate from mouse clicks, complete with code examples and visual screenshots of the resulting effect.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Create Expanding Ripple Effects with Pygame: A Step-by-Step Guide

When the mouse is clicked, a circle expands outward from the cursor like a ripple, with random size and color, stopping after reaching a random radius.

Example screenshots of the effect:

The implementation uses Pygame. The script initializes a 600×400 window, maintains up to ten circles, and on each mouse click creates a new circle with a random RGB color and radius growth. The main loop updates radii, draws circles, and removes them once they exceed a random maximum size.

import pygame, random, sys, time
pygame.init()
screen = pygame.display.set_mode([600, 400])
screen.fill((255, 255, 255))
radiusr = 0
arrradiusr = [0] * 10  # circle radii
arraddradiusr = [0] * 10  # radius increments
arrradiusbool = [False] * 10  # existence flag
arrradiusx = [0] * 10  # x positions
arrradiusy = [0] * 10  # y positions
RGBx = [0] * 10
RGBy = [0] * 10
RGBz = [0] * 10

while True:
    time.sleep(0.1)
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN:
            num = arrradiusbool.index(False)
            arrradiusbool[num] = True
            arrradiusr[num] = 0
            arrradiusx[num], arrradiusy[num] = pygame.mouse.get_pos()
            RGBx[num] = random.randint(0, 255)
            RGBy[num] = random.randint(0, 255)
            RGBz[num] = random.randint(0, 255)
            pygame.draw.circle(screen, pygame.Color(RGBx[num], RGBy[num], RGBz[num]),
                               (arrradiusx[num], arrradiusy[num]), arrradiusr[num], 1)
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    for i in range(10):
        if not arrradiusbool[i]:
            continue
        if arrradiusr[i] < random.randint(10, 50):
            arraddradiusr[i] = random.randint(0, 5)
            arrradiusr[i] += arraddradiusr[i]
            pygame.draw.circle(screen, pygame.Color(RGBx[i], RGBy[i], RGBz[i]),
                               (arrradiusx[i], arrradiusy[i]), arrradiusr[i], 1)
        else:
            arrradiusbool[i] = False
    pygame.display.update()
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GraphicsPythonGame DevelopmentPygameripple effect
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.