Code:
import turtle
import time
s = turtle.Screen()
s.bgcolor("#0B0614")
s.setup(700, 700)
s.tracer(0)
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.pensize(2)
colors = ["#FFD166", "#FF5DA2", "#55F7E8", "#B388FF"]
for i in range(36):
t.pencolor(colors[i % 4])
t.circle(100, 60)
t.left(120)
t.circle(100, 60)
t.left(120)
t.right(10)
s.update()
time.sleep(0.4)
for r in [130, 160, 190, 220]:
t.penup()
t.goto(0, -r)
t.setheading(0)
t.pendown()
t.pencolor("#FFD166")
t.circle(r, steps=360)
s.update()
time.sleep(1)
turtle.done()
Explanation:
1. Import Libraries
import turtleimport time
- turtle — draws shapes and patterns.
- time — adds delays to slow down the animation.
2. Create the Screen
s = turtle.Screen()s.bgcolor("#0B0614")s.setup(700, 700)s.tracer(0)
- Creates a Turtle graphics window.
- Sets a dark purple background.
- Sets the window size to 700 × 700 pixels.
- tracer(0) disables automatic screen updates for controlled animation.
3. Configure the Turtle
t = turtle.Turtle()t.hideturtle()t.speed(0)t.pensize(2)
- Creates the drawing turtle.
- Hides the turtle cursor.
- Sets the drawing speed to maximum.
- Sets the pen thickness to 2.
4. Define Neon Colors
colors = ["#FFD166", "#FF5DA2", "#55F7E8", "#B388FF"]
Defines four colors: golden yellow, pink, turquoise, and purple.
5. Draw the Flower Pattern
for i in range(36): t.pencolor(colors[i % 4]) t.circle(100, 60) t.left(120) t.circle(100, 60) t.left(120) t.right(10) s.update() time.sleep(0.4)
- range(36) repeats the drawing 36 times.
- colors[i % 4] cycles through the four colors.
- circle(100, 60) draws a curved arc with radius 100 and extent 60°.
- left(120) turns the turtle 120° to create the petal-like curves.
- right(10) slightly rotates the pattern after each iteration.
- s.update() refreshes the screen.
- time.sleep(0.4) pauses for 0.4 seconds.
6. Draw Concentric Circles
for r in [130, 160, 190, 220]:
Repeats the loop for four circle radii: 130, 160, 190, and 220.
t.penup()t.goto(0, -r)t.setheading(0)t.pendown()
- Lifts the pen to move without drawing.
- Moves to the bottom point of the circle.
- Sets the turtle's direction to 0°.
- Lowers the pen to begin drawing.
t.pencolor("#FFD166")t.circle(r, steps=360)
- Sets the pen color to golden yellow.
- Draws a smooth circle using 360 steps.
s.update()time.sleep(1)
Updates the screen and pauses for one second after each circle.
7. Finish the Program
turtle.done()
Keeps the Turtle graphics window open after drawing is complete.


0 Comments:
Post a Comment