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)
t.width(2)
colors = [
"#ff006e", "#ff7b00", "#ffe600",
"#00ff9d", "#00e5ff", "#4169ff",
"#9b30ff", "#ff00d4"
]
def ring(radius, color, offset=0):
t.color(color)
t.penup()
t.goto(radius, 0)
t.setheading(90 + offset)
t.pendown()
for _ in range(360):
t.forward(2 * math.pi * radius / 360)
t.left(1)
screen.update()
time.sleep(0.002)
for r in range(240, 80, -20):
ring(r, colors[(r // 20) % len(colors)], r / 8)
t.color("#ffffff")
t.width(4)
t.penup()
t.goto(-210, 0)
t.setheading(0)
t.pendown()
for _ in range(70):
t.forward(6)
t.left(2.5)
screen.update()
time.sleep(0.008)
for _ in range(70):
t.forward(6)
t.right(2.5)
screen.update()
time.sleep(0.008)
t.penup()
t.goto(0, -55)
t.color("#050510")
t.begin_fill()
t.circle(55)
t.end_fill()
t.goto(0, -25)
t.color("#00ffff")
t.begin_fill()
t.circle(25)
t.end_fill()
t.goto(0, -10)
t.color("white")
t.begin_fill()
t.circle(10)
t.end_fill()
screen.update()
turtle.done()
Explanation:
1. Importing Required Libraries
import turtle
import math
import time
import turtle
Imports Python's built-in Turtle Graphics library for creating the animation.
import math
Imports mathematical functions. Here, math.pi is used to calculate the circumference of the rings.
import time
Imports the time module. It is used to add small delays with time.sleep().
2. Creating the Turtle Screen
screen = turtle.Screen()
Creates a Turtle graphics window and stores it in the variable screen.
screen.setup(800, 800)
Sets the window size to 800 × 800 pixels.
screen.bgcolor("#020208")
Sets a very dark blue-black background.
This makes the neon colors stand out.
3. Creating the Turtle
t = turtle.Turtle()
Creates a Turtle object and stores it in t.
This Turtle will perform all the drawing.
t.hideturtle()
Hides the Turtle cursor so that it doesn't appear over the final artwork.
t.speed(0)
Sets the Turtle's drawing speed to the fastest setting.
t.width(2)
Sets the initial pen width to 2.
4. Defining the Neon Color Palette
colors = [
"#ff006e", "#ff7b00", "#ffe600",
"#00ff9d", "#00e5ff", "#4169ff",
"#9b30ff", "#ff00d4"
]
Creates a list containing 8 neon colors.
These colors are used for the orbital rings.
The palette contains neon shades of:
Pink
Orange
Yellow
Green
Cyan
Blue
Purple
Magenta
5. Creating the ring() Function
def ring(radius, color, offset=0):
Defines a reusable function named ring().
It accepts three parameters:
radius
Controls the size of the ring.
color
Controls the ring's color.
offset=0
Controls the initial rotation of the Turtle.
If no offset is provided, the default value is 0.
6. Setting the Ring Color
t.color(color)
Sets the Turtle's pen color to the color passed to the function.
For example:
ring(200, "#00e5ff")
would draw a cyan ring.
7. Moving to the Ring's Starting Position
t.penup()
Lifts the pen so the Turtle can move without drawing.
t.goto(radius, 0)
Moves the Turtle to:
(radius, 0)
For example, if radius = 200, the Turtle moves to:
(200, 0)
This is a point on the right side of an imaginary circle centered at (0, 0).
8. Setting the Ring's Direction
t.setheading(90 + offset)
Sets the Turtle's initial direction.
Normally:
90° → Up
The offset rotates this starting direction.
For example:
offset = 0
→ 90°
offset = 20
→ 110°
offset = 30
→ 120°
This gives the rings different orientations.
9. Starting the Drawing
t.pendown()
Places the pen down so the Turtle begins drawing.
10. Drawing the Circular Ring
for _ in range(360):
Runs the loop 360 times.
Each iteration represents approximately one degree of rotation.
t.forward(2 * math.pi * radius / 360)
Calculates how far the Turtle should move during each step.
The formula:
2 × π × radius
calculates the circumference of the circle.
Dividing it by 360 gives the approximate distance for one degree.
So this line helps create a smooth circular path.
t.left(1)
Turns the Turtle left by 1°.
After 360 iterations:
360 × 1° = 360°
Therefore, the Turtle completes one full revolution.
screen.update()
Manually updates the screen.
This allows us to see the ring being drawn progressively.
time.sleep(0.002)
Pauses the program for 0.002 seconds.
This creates the animated drawing effect.
11. Creating Multiple Rings
for r in range(240, 80, -20):
Creates rings with different radii.
The values generated are:
240
220
200
180
160
140
120
100
So the program creates 8 rings.
The radius decreases by 20 each time.
12. Selecting a Color for Each Ring
colors[(r // 20) % len(colors)]
Selects a color from the colors list.
r // 20
Performs integer division.
For example:
240 // 20 = 12
220 // 20 = 11
200 // 20 = 10
len(colors)
There are 8 colors, so:
len(colors)
returns:
8
%
The modulo operator keeps the index within the valid range of the list.
This makes the colors repeat cyclically.
13. Creating a Ring Offset
r / 8
Calculates a rotation offset based on the radius.
For example:
240 / 8 = 30
200 / 8 = 25
160 / 8 = 20
So each ring gets a slightly different orientation.
14. Calling the ring() Function
ring(r, colors[(r // 20) % len(colors)], r / 8)
Calls the ring() function with three values:
r
↓
Ring size
colors[...]
↓
Ring color
r / 8
↓
Ring rotation
This creates all the colorful orbital rings.
15. Changing the Pen for the Central Wave
t.color("#ffffff")
Changes the Turtle's color to white.
t.width(4)
Increases the pen width from 2 to 4.
The thicker line makes the central wave more visible.
16. Positioning the Central Wave
t.penup()
Lifts the pen while moving.
t.goto(-210, 0)
Moves the Turtle to the left side of the design.
t.setheading(0)
Sets the Turtle's direction to 0°, which points to the right.
t.pendown()
Places the pen down and prepares to draw.
17. Drawing the First Half of the Wave
for _ in range(70):
Runs the loop 70 times.
t.forward(6)
Moves the Turtle forward by 6 units.
t.left(2.5)
Turns the Turtle left by 2.5°.
Repeated small movements and rotations create a smooth curved line.
screen.update()
Updates the screen during the animation.
time.sleep(0.008)
Adds a small delay so the wave appears gradually.
18. Drawing the Second Half of the Wave
for _ in range(70):
Starts another 70-iteration loop.
t.forward(6)
Moves forward by 6 units.
t.right(2.5)
Now turns right by 2.5°.
The direction changes from left to right, creating the opposite curve.
screen.update()
Updates the screen.
time.sleep(0.008)
Adds a small animation delay.
Together, the two loops create the white wave-like structure across the center.
19. Creating the Dark Outer Core
t.penup()
Lifts the pen.
t.goto(0, -55)
Moves the Turtle to the correct position for drawing a circle centered around the origin.
t.color("#050510")
Sets a very dark color.
t.begin_fill()
Starts the filling process.
t.circle(55)
Draws a circle with radius 55.
t.end_fill()
Fills the circle with the selected dark color.
This creates the dark outer core.
20. Creating the Cyan Inner Core
t.goto(0, -25)
Moves the Turtle to the position for a smaller circle.
t.color("#00ffff")
Changes the color to bright cyan.
t.begin_fill()
Starts filling the next shape.
t.circle(25)
Draws a circle with radius 25.
t.end_fill()
Fills the circle with cyan.
This creates the glowing cyan inner layer.
21. Creating the White Center
t.goto(0, -10)
Moves the Turtle to the position for the smallest circle.
t.color("white")
Changes the color to white.
t.begin_fill()
Starts the filling process.
t.circle(10)
Draws a small circle with radius 10.
t.end_fill()
Fills the circle with white.
This creates the bright center of the energy core.
22. Final Screen Update
screen.update()
Performs a final screen refresh to make sure the complete artwork is displayed.
23. Keeping the Window Open
turtle.done()
Keeps the Turtle graphics window open after the program finishes.

0 Comments:
Post a Comment