Sunday, 4 October 2026

๐ŸŒŒ Python Turtle The Neon Ribbon Orbit


 



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 × 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.




0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (346) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (359) Bootcamp (16) C (78) C# (12) C++ (83) cloud (1) Course (93) Coursera (305) Cybersecurity (36) data (10) Data Analysis (47) Data Analytics (31) data management (16) Data Science (435) Data Strucures (19) Deep Learning (222) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (9) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Generative AI (78) Git (13) Google (55) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (407) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (35) Python (1377) Python Coding Challenge (1265) Python Library (19) Python Mathematics (19) Python Mistakes (51) Python Pattern Challenge (16) Python Quiz (649) Python Tips (112) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (21) SQL (55) Udemy (22) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)