import turtle
import random
# Set up screen
screen = turtle.Screen()
screen.bgcolor("black")
screen.title("Fireworks")
# Create turtle
t = turtle.Turtle()
t.speed(0)
t.hideturtle()
# Define functions
def draw_star(x, y, size, pen):
pen.penup()
pen.goto(x, y)
pen.pendown()
pen.begin_fill()
for i in range(5):
pen.forward(size)
pen.right(144)
pen.end_fill()
def draw_explosion(x, y, pen):
pen.color(random.choice(["red", "orange", "yellow", "green", "blue", "purple"]))
pen.penup()
pen.goto(x, y)
pen.pendown()
for i in range(25):
pen.begin_fill()
pen.circle(2 * i)
pen.end_fill()
# Main loop
while True:
x = random.randint(-300, 300)
y = random.randint(-200, 200)
size = random.randint(10, 80)
draw_explosion(x, y, t)
for i in range(5):
draw_star(x, y, size, t)
turtle.update()
This code creates a fireworks animation with random explosions and stars in different colors. The draw_star function draws a star at the specified coordinates and size, and the draw_explosion function draws a random explosion at the specified coordinates. The main loop generates random coordinates and sizes for each firework and calls the necessary functions to draw the animation.