Code:
import turtle
import time
import colorsys
s = turtle.Screen()
s.setup(750, 750)
s.bgcolor("black")
s.title("Rainbow Hypnotic Vortex")
s.tracer(0)
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.pensize(2)
for i in range(180):
t.pencolor(colorsys.hsv_to_rgb(i / 180, 1, 1))
t.penup()
t.goto(0, 0)
t.setheading(i * 7)
t.pendown()
length = 80 + i * 1.8
for _ in range(2):
t.forward(length)
t.circle(35 + i * 0.15, 90)
s.update()
time.sleep(0.025)
turtle.done()
Explanation:
1. Import Libraries
import turtleimport timeimport colorsys
- turtle – draws the vortex pattern.
- time – adds animation delays.
- colorsys – generates rainbow colors using HSV color values.
2. Create the Screen
s = turtle.Screen()s.setup(750, 750)s.bgcolor("black")s.title("Rainbow Hypnotic Vortex")s.tracer(0)
- Creates a 750 × 750 graphics window.
- Sets the background to black.
- Adds the window title.
- tracer(0) disables automatic screen updates.
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 fastest drawing speed.
- Sets the pen thickness to 2.
4. Create the Main Loop
for i in range(180):
Repeats the drawing process 180 times to create multiple rotating patterns.
5. Generate Rainbow Colors
t.pencolor(colorsys.hsv_to_rgb(i / 180, 1, 1))
- Converts HSV color values into RGB.
- i / 180 gradually changes the hue.
- 1 represents full saturation.
- 1 represents full brightness.
- Produces a continuous rainbow color effect.
6. Set the Drawing Position
t.penup()t.goto(0, 0)t.setheading(i * 7)t.pendown()
- Lifts the pen to avoid unwanted lines.
- Moves the turtle to the center.
- Rotates the direction by 7° on each iteration.
- Puts the pen down to start drawing.
7. Calculate the Pattern Length
length = 80 + i * 1.8
- Starts with a length of 80 units.
- Increases the length by 1.8 units per iteration.
- Creates progressively larger patterns.
8. Draw the Curved Vortex
for _ in range(2): t.forward(length) t.circle(35 + i * 0.15, 90)
- Repeats the drawing movement twice.
- forward(length) draws a straight line.
- circle() creates a curved arc.
- The circle radius gradually increases with i.
- Combines straight and curved movements to create the vortex effect.
9. Animate the Drawing
s.update()time.sleep(0.025)
- s.update() refreshes the screen manually.
- time.sleep(0.025) pauses for 0.025 seconds.
- Makes the drawing animation visible.
10. Finish the Program
turtle.done()
Keeps the Turtle graphics window open after the artwork is complete.
Output:

