Creating a Fireworks Display in Python with Multiple AI Models

The idea began after watching a fireworks simulation video on Bilibili, allegedly generated by a Python script. The uploader required viewers to follow, like, and comment before sending a private message to receive the source code. After jumping through several hoops—inlcuding forum registration and virtual currency purchases—the promised code remained elusive.

This led to an alternative approach: asking four major Chinese large language models—ERNIE Bot (Wenxin Yiyan), Qwen (Tongyi Qianwen), GLM (Zhipu Qingyan), and Skywork—to each generate a Python-based fireworks display. The results were then tested locally for visual appeal and correctness.

ERNIE Bot (Wenxin Yiyan)

Used the turtle module to simulate fireworks launching from the bottom center of the screen, exploding into colored circles at random angles and heights.

import turtle
import random

screen = turtle.Screen()
screen.bgcolor("black")
launcher = turtle.Turtle()
launcher.hideturtle()
launcher.speed(0)
launcher.penup()
launcher.goto(0, -200)

def explode(x, y):
    particle = turtle.Turtle()
    particle.hideturtle()
    particle.speed(0)
    particle.penup()
    particle.goto(x, y)
    particle.color(random.choice(["red", "orange", "yellow", "green", "blue", "purple"]))
    particle.pendown()
    particle.begin_fill()
    for _ in range(36):
        particle.forward(10)
        particle.right(10)
    particle.end_fill()

def launch():
    angle = random.randint(0, 360)
    power = random.randint(5, 15)
    launcher.setheading(angle)
    launcher.forward(power)
    explode(launcher.xcor(), launcher.ycor())
    launcher.home()

while True:
    launch()
    screen.update()
    screen.ontimer(lambda: None, 50)

Result: Repeated circular bursts at the top. Functional but simplistic. Score: 5/10.

Qwen (Tongyi Qianwen)

Used matplotlib.animation.FuncAnimation to simulate multiple fireworks with trajectories and fading particles.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import random

fig, ax = plt.subplots(figsize=(8, 8))
fireworks = []
for _ in range(10):
    x = random.uniform(-2, 2)
    y = random.uniform(-2, 2)
    vx = random.uniform(-1, 1)
    vy = random.uniform(3, 6)
    color = (random.random(), random.random(), random.random())
    fireworks.append([x, y, vx, vy, color])

def update(frame):
    ax.clear()
    for fw in fireworks:
        x, y, vx, vy, color = fw
        x += vx
        y -= vy
        vy -= 0.5
        if y < -2 or y > 2:
            fw[0] = random.uniform(-2, 2)
            fw[1] = random.uniform(-2, 2)
            fw[2] = random.uniform(-1, 1)
            fw[3] = random.uniform(3, 6)
        ax.plot([x, x], [y, 0], c=color, alpha=0.7)
        ax.scatter(x, y, s=abs(vy)*40, c=color, alpha=0.9)
    ax.set_xlim(-3, 3)
    ax.set_ylim(-3, 3)
    ax.axis('off')

ani = FuncAnimation(fig, update, interval=50)
plt.show()

Result: Daytime-like trails without clear explosions. Lacked visual impact. Score: 4/10.

GLM (Zhipu Qingyan)

Provided a minimal matplotlib animation showing a single parabolic trajectory without explosion effects.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation

plt.style.use('dark_background')
fig, ax = plt.subplots()
ax.set_xlim(-5, 5)
ax.set_ylim(0, 10)
points, = ax.plot([], [], 'wo')

def generate_firework(start, end):
    t = np.linspace(0, 2, 40)
    x = start + (end - start) * t
    y = -0.5 * 9.81 * t**2 + 10  # Adjusted for upward launch
    return x, y

x_traj, y_traj = generate_firework(-1, 1)

def update(frame):
    points.set_data(x_traj[:frame], y_traj[:frame])
    return points,

ani = FuncAnimation(fig, update, frames=40, blit=True)
plt.show()

Result: Only a single white dot moving along a curve—no explosion or multi-particle effect. Score: 1/10.

Skywork (Tiangong)

Used turtle to draw static fireworks with radial lines simulating bursts.

import turtle
import random

screen = turtle.Screen()
screen.bgcolor("black")
screen.title("Fireworks Show")

def create_burst(x, y):
    burst = turtle.Turtle()
    burst.color(random.choice(["red", "orange", "yellow", "green", "blue", "purple", "white"]))
    burst.penup()
    burst.goto(x, y)
    burst.pendown()
    burst.speed(0)
    for _ in range(36):
        burst.forward(random.randint(50, 100))
        burst.backward(random.randint(50, 100))
        burst.right(10)
    burst.hideturtle()

for _ in range(20):
    create_burst(random.randint(-200, 200), random.randint(100, 200))

turtle.done()

Result: Visually recognizable fireworks with radial streaks. Most satisfying among the four. Score: 7/10.

Final subjective ranking: Skywork > ERNIE Bot > Qwen > GLM.

Tags: python turtle matplotlib animation fireworks-simulation

Posted on Thu, 09 Jul 2026 17:15:44 +0000 by sweetmaster