Code:
import turtle
import math
import time
screen = turtle.Screen()
screen.setup(800, 800)
screen.bgcolor("#020208")
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
colors = [
"#00f5ff",
"#2979ff",
"#7c4dff",
"#d500f9",
"#ff2d75",
"#ff6d00",
"#ffe600"
]
def draw_ring(radius, rotation, color):
"""Draw one rotating polygon ring."""
points = 10
t.color(color)
t.width(2)
for i in range(points + 1):
angle = rotation + i * (360 / points)
x = radius * math.cos(math.radians(angle))
y = radius * math.sin(math.radians(angle))
if i == 0:
t.penup()
t.goto(x, y)
t.pendown()
else:
t.goto(x, y)
screen.update()
time.sleep(0.004)
# --------------------------------
# Outer → Inner tunnel
# --------------------------------
for i in range(55):
radius = 270 - i * 4.6
rotation = i * 6
draw_ring(
radius,
rotation,
colors[i % len(colors)]
)
time.sleep(0.025)
# --------------------------------
# Inner spiral
# --------------------------------
t.width(3)
t.penup()
t.goto(0, 0)
t.pendown()
for i in range(220):
radius = i * 0.65
angle = i * 13
x = radius * math.cos(math.radians(angle))
y = radius * math.sin(math.radians(angle))
t.color(colors[i % len(colors)])
t.goto(x, y)
screen.update()
time.sleep(0.006)
# --------------------------------
# Glowing center
# --------------------------------
for r in range(30, 2, -3):
t.penup()
t.goto(0, -r)
t.dot(r, colors[r % len(colors)])
screen.update()
time.sleep(0.04)
t.penup()
t.goto(0, -5)
t.dot(8, "white")
screen.update()
turtle.done()
Explanation:
1. Import Libraries
import turtle
import math
import time
turtle → Used for drawing.
math → Used for trigonometric calculations.
time → Used to control animation speed.
2. Create the Screen
screen = turtle.Screen()
screen.setup(800, 800)
screen.bgcolor("#020208")
Creates the Turtle window.
Sets the size to 800 × 800.
Gives the screen a dark background.
3. Create the Turtle
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
Creates the drawing turtle.
Hides the turtle cursor.
Sets the fastest drawing speed.
4. Define Neon Colors
colors = [
"#00f5ff",
"#2979ff",
"#7c4dff",
"#d500f9",
"#ff2d75",
"#ff6d00",
"#ffe600"
]
Stores multiple neon colors.
These colors are reused throughout the animation.
5. Create the Ring Function
def draw_ring(radius, rotation, color):
Defines a function for drawing one polygon ring.
radius controls size.
rotation controls angle.
color controls the ring color.
6. Set Ring Properties
points = 10
t.color(color)
t.width(2)
Each ring has 10 points.
Sets the drawing color.
Sets line thickness to 2.
7. Loop Through Points
for i in range(points + 1):
Loops through all polygon points.
+1 closes the polygon.
8. Calculate the Angle
angle = rotation + i * (360 / points)
Divides the circle into equal sections.
Adds rotation to make each ring turn.
9. Calculate X Position
x = radius * math.cos(math.radians(angle))
Converts the angle to radians.
Calculates the X coordinate.
10. Calculate Y Position
y = radius * math.sin(math.radians(angle))
Calculates the Y coordinate using sine.
11. Move to the First Point
if i == 0:
t.penup()
t.goto(x, y)
t.pendown()
Moves to the first point without drawing.
Then puts the pen down to start drawing.
12. Connect the Points
else:
t.goto(x, y)
Moves between points.
Creates the polygon ring.
13. Create Animation
screen.update()
time.sleep(0.004)
Updates the screen.
Adds a tiny delay for smooth animation.
14. Create the Outer Tunnel
for i in range(55):
Creates 55 rings.
radius = 270 - i * 4.6
Gradually decreases the ring size.
Creates the tunnel effect.
rotation = i * 6
Rotates every new ring.
draw_ring(radius, rotation, colors[i % len(colors)])
Draws each ring.
Cycles through the neon colors.
15. Create the Inner Spiral
t.width(3)
Makes the spiral line thicker.
t.penup()
t.goto(0, 0)
t.pendown()
Starts the spiral from the center.
for i in range(220):
Generates 220 spiral points.
radius = i * 0.65
angle = i * 13
Radius gradually increases.
Angle continuously rotates.
x = radius * math.cos(math.radians(angle))
y = radius * math.sin(math.radians(angle))
Calculates each spiral point.
t.color(colors[i % len(colors)])
t.goto(x, y)
Changes the color.
Draws the spiral.
16. Create the Glowing Center
for r in range(30, 2, -3):
Creates several circles.
Each circle becomes smaller.
t.penup()
t.goto(0, -r)
Positions the turtle for the glow.
t.dot(r, colors[r % len(colors)])
Draws colored dots.
Creates the glowing-center effect.
17. Add the White Core
t.penup()
t.goto(0, -5)
t.dot(8, "white")
Adds a small white dot.
Creates the bright center.
18. Finish the Animation
screen.update()
turtle.done()
Updates the final frame.
Keeps the Turtle window open.

0 Comments:
Post a Comment