import turtle
# Create a turtle screen
screen = turtle.Screen()
# Create a turtle object
t = turtle.Turtle()
# Set turtle speed
t.speed(1)
# Function to change the pen color every 50 steps
def change_color():
colors = ["red", "green", "blue", "orange", "purple"] # List of colors
current_color = 0 # Index of the current color
for _ in range(50):
t.forward(1) # Move the turtle forward by 1 unit
if _ % 10 == 0:
# Change color every 10 steps
current_color = (current_color + 1) % len(colors)
t.pencolor(colors[current_color])
# Position the turtle
t.penup()
t.goto(-100, 0) # Adjust the starting position
t.pendown()
# Draw the line with changing colors
change_color()
# Close the screen on click
screen.exitonclick()
To embed this program on your website, copy the following code and paste it into your website's HTML: