Untitled

 avatar
unknown
plain_text
11 days ago
1.0 kB
3
Indexable
import turtle
import random

# Set up the screen
wn = turtle.Screen()
wn.bgcolor("black")

# Create turtle for the candle
candle = turtle.Turtle()
candle.color("white")
candle.shape("square")
candle.shapesize(stretch_wid=8, stretch_len=1)

# Create turtle for the flame
flame = turtle.Turtle()
flame.color("orange")
flame.shape("triangle")
flame.shapesize(stretch_wid=1, stretch_len=2)

# Function to draw sparks
def draw_sparks():
    sparks = turtle.Turtle()
    sparks.hideturtle()
    sparks.color("yellow")
    for _ in range(10):  # Draw 10 sparks
        x = random.randint(-50, 50)
        y = random.randint(100, 150)
        sparks.penup()
        sparks.goto(x, y)
        sparks.pendown()
        sparks.dot()

# Position candle and flame
candle.penup()
candle.goto(0, -50)
candle.stamp()

flame.penup()
flame.goto(0, 50)
flame.stamp()

# Draw sparks
draw_sparks()

# Hide the turtles
candle.hideturtle()
flame.hideturtle()

# Keep the window open
turtle.done()
Leave a Comment