Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
1
Indexable
Never
import pygame
import time

pygame.init()

# Set up the window
size = width, height = 640, 480
screen = pygame.display.set_mode(size)

# Define the colors
white = (255, 255, 255)
green = (0, 255, 0)

# Define the initial position and size of the stem and flower
stem_x, stem_y = 320, 480
stem_height = 0
flower_x, flower_y = 300, 380
flower_radius = 0

# Define the animation speed and duration
animation_speed = 2
animation_duration = 5

# Define the function to draw the stem and flower
def draw_flower():
    pygame.draw.line(screen, green, (stem_x, stem_y), (stem_x, stem_y - stem_height), 10)
    pygame.draw.circle(screen, white, (flower_x, flower_y), flower_radius)

# Main animation loop
start_time = time.time()
while True:
    # Handle events
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    # Calculate the elapsed time and animation progress
    elapsed_time = time.time() - start_time
    progress = min(elapsed_time / animation_duration, 1)

    # Update the stem and flower size
    stem_height = int(progress * 100)
    flower_radius = int(progress * 50)

    # Clear the screen and draw the flower
    screen.fill((0, 0, 0))
    draw_flower()

    # Update the display
    pygame.display.flip()

    # Wait for a short time before continuing
    pygame.time.wait(animation_speed)

    # End the animation if it's complete
    if elapsed_time >= animation_duration:
        break

# Wait for the user to close the window
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()