Code:
import turtle
import math
import time
screen = turtle.Screen()
screen.setup(700, 700)
screen.bgcolor("#020208")
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.width(2)
colors = [
"#00ffff", "#7c4dff",
"#ff2d75", "#00ff9d",
"#ffe600"
]
for layer in range(28):
t.color(colors[layer % len(colors)])
t.penup()
for i in range(180):
a = math.radians(i * 2)
x = 230 * math.sin(a)
y = 110 * math.sin(a * 2)
# Rotate each ribbon
r = math.radians(layer * 6)
X = x * math.cos(r) - y * math.sin(r)
Y = x * math.sin(r) + y * math.cos(r)
if i == 0:
t.goto(X, Y)
t.pendown()
else:
t.goto(X, Y)
screen.update()
time.sleep(0.002)
time.sleep(0.06)
# ✨ Center
t.penup()
t.goto(0, -12)
t.dot(24, "#ffffff")
screen.update()
time.sleep(2)
turtle.done()
Explanation:
1. Import Libraries
import turtle
import math
import time
turtle → Used for drawing.
math → Used for mathematical calculations.
time → Controls animation speed.
2. Create the Screen
screen = turtle.Screen()
screen.setup(700, 700)
screen.bgcolor("#020208")
Creates a 700 × 700 canvas.
Sets a dark background.
3. Configure the Turtle
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.width(2)
Creates the turtle.
Hides the turtle cursor.
Sets maximum drawing speed.
Sets line thickness to 2.
4. Define Neon Colors
colors = [
"#00ffff", "#7c4dff",
"#ff2d75", "#00ff9d",
"#ffe600"
]
Stores five neon colors.
Colors are reused for each ribbon.
5. Create Multiple Ribbons
for layer in range(28):
Creates 28 rotating ribbon layers.
6. Select Ribbon Color
t.color(colors[layer % len(colors)])
t.penup()
Cycles through the neon colors.
Lifts the pen before moving to the starting point.
7. Generate Ribbon Points
for i in range(180):
Creates 180 points for each ribbon.
More points make the curve smoother.
8. Calculate the Angle
a = math.radians(i * 2)
Converts the angle from degrees to radians.
The angle increases by 2° each step.
9. Calculate X Coordinate
x = 230 * math.sin(a)
Uses a sine wave to create horizontal movement.
230 controls the ribbon's width.
10. Calculate Y Coordinate
y = 110 * math.sin(a * 2)
Creates the vertical wave.
a * 2 makes the wave oscillate faster.
11. Calculate Ribbon Rotation
r = math.radians(layer * 6)
Gives every layer a different rotation.
Each new ribbon rotates by 6°.
12. Calculate Rotated X Coordinate
X = x * math.cos(r) - y * math.sin(r)
Applies a mathematical rotation to the X coordinate.
13. Calculate Rotated Y Coordinate
Y = x * math.sin(r) + y * math.cos(r)
Applies the same rotation to the Y coordinate.
Together, X and Y create the rotated ribbon.
14. Start the Ribbon
if i == 0:
t.goto(X, Y)
t.pendown()
Moves to the first point without drawing.
Starts drawing from the first point.
15. Continue Drawing
else:
t.goto(X, Y)
Connects each calculated point.
Forms the smooth ribbon curve.
16. Animate the Ribbon
screen.update()
time.sleep(0.002)
Updates the screen.
Adds a tiny delay for smooth animation.
17. Pause Between Ribbons
time.sleep(0.06)
Adds a short pause after each ribbon.
Makes the layered animation easier to see.
18. Add the Center Glow
t.penup()
t.goto(0, -12)
t.dot(24, "#ffffff")
Moves to the center.
Adds a white glowing dot.
19. Display the Final Design
screen.update()
time.sleep(2)
Updates the final drawing.
Keeps it visible for 2 seconds.
20. Finish
turtle.done()
Keeps the Turtle window open.
Ends the program.
1. Import Libraries
import turtle import math import time
-
turtle→ Used for drawing. -
math→ Used for mathematical calculations. -
time→ Controls animation speed.
2. Create the Screen
screen = turtle.Screen() screen.setup(700, 700) screen.bgcolor("#020208")
-
Creates a
700 × 700canvas. - Sets a dark background.
3. Configure the Turtle
t = turtle.Turtle() t.hideturtle() t.speed(0) t.width(2)
- Creates the turtle.
- Hides the turtle cursor.
- Sets maximum drawing speed.
-
Sets line thickness to
2.
4. Define Neon Colors
colors = [ "#00ffff", "#7c4dff", "#ff2d75", "#00ff9d", "#ffe600" ]
- Stores five neon colors.
- Colors are reused for each ribbon.
5. Create Multiple Ribbons
for layer in range(28):
-
Creates
28rotating ribbon layers.
6. Select Ribbon Color
t.color(colors[layer % len(colors)]) t.penup()
- Cycles through the neon colors.
- Lifts the pen before moving to the starting point.
7. Generate Ribbon Points
for i in range(180):
-
Creates
180points for each ribbon. - More points make the curve smoother.
8. Calculate the Angle
a = math.radians(i * 2)
- Converts the angle from degrees to radians.
-
The angle increases by
2°each step.
9. Calculate X Coordinate
x = 230 * math.sin(a)
- Uses a sine wave to create horizontal movement.
-
230controls the ribbon's width.
10. Calculate Y Coordinate
y = 110 * math.sin(a * 2)
- Creates the vertical wave.
-
a * 2makes the wave oscillate faster.
11. Calculate Ribbon Rotation
r = math.radians(layer * 6)
- Gives every layer a different rotation.
-
Each new ribbon rotates by
6°.
12. Calculate Rotated X Coordinate
X = x * math.cos(r) - y * math.sin(r)
- Applies a mathematical rotation to the X coordinate.
13. Calculate Rotated Y Coordinate
Y = x * math.sin(r) + y * math.cos(r)
- Applies the same rotation to the Y coordinate.
-
Together,
XandYcreate the rotated ribbon.
14. Start the Ribbon
if i == 0: t.goto(X, Y) t.pendown()
- Moves to the first point without drawing.
- Starts drawing from the first point.
15. Continue Drawing
else: t.goto(X, Y)
- Connects each calculated point.
- Forms the smooth ribbon curve.
16. Animate the Ribbon
screen.update() time.sleep(0.002)
- Updates the screen.
- Adds a tiny delay for smooth animation.
17. Pause Between Ribbons
time.sleep(0.06)
- Adds a short pause after each ribbon.
- Makes the layered animation easier to see.
18. Add the Center Glow
t.penup() t.goto(0, -12) t.dot(24, "#ffffff")
- Moves to the center.
- Adds a white glowing dot.
19. Display the Final Design
screen.update() time.sleep(2)
- Updates the final drawing.
- Keeps it visible for 2 seconds.
20. Finish
turtle.done()
- Keeps the Turtle window open.
- Ends the program.

0 Comments:
Post a Comment