I'm trying to make my first game in pygame.
I want the game to have this animation in the background
I'm using python 3.9.2
import pygame, math, random, sys
from pygame.locals import *
screen = pygame.display.set_mode((400, 400))
fps = 60
pygame.init()
mainClock = pygame.time.Clock()
# Colors
black = (0, 0, 0)
white = (255, 255, 255)
# Function for close the game ------------------------------------------------------------------------------------------------------------
def close_game():
pygame.quit()
sys.exit()
# Functions for drawing ------------------------------------------------------------------------------------------------------------------
def background():
screen.fill(black)
def canvas():
margin = pygame.draw.rect(screen, white, (50, 50, 300, 300), 1)
def bar_animation():
bar_width = 15
for b in range(0, 20):
bar_b_height = random.randint(10, 100)
bar_b = pygame.draw.rect(screen, white, (50 + (bar_width * b), 350 - bar_b_height, bar_width, bar_b_height), 0)
# Main game loop --------------------------------------------------------------------------------------------------------------------------
def main_loop():
running = True
while running:
background()
bar_animation()
canvas()
for event in pygame.event.get():
if event.type == QUIT:
close_game()
pass
pygame.display.update()
mainClock.tick(fps)
# Run game --
main_loop()
On that code, I recreated what I want for the background of my game. I want to have the bar_animation() function running slower without making the whole game or other functions run slower...
That code produce something like this:

i recommend you to execute the code to understand what im doing
