You can download this code by clicking the button below.
This code is now available for download.
This function uses the random module from the pygame library to generate random colors, and then draws a random-sized circle at a random position on the screen.
Technology Stack : pygame, random
Code Type : Graphics drawing
Code Difficulty : Intermediate
import pygame
import random
def random_color():
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
return (r, g, b)
def draw_random_circle(screen):
color = random_color()
position = (random.randint(0, screen.get_width()), random.randint(0, screen.get_height()))
size = random.randint(10, 100)
pygame.draw.circle(screen, color, position, size)