Code:
import turtle
import math
import time
screen = turtle.Screen()
screen.setup(650, 650)
screen.bgcolor("#080014")
screen.tracer(0)
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.width(2)
colors = ["#ff4d8d", "#ff8fab", "#c77dff", "#7b2cff", "#00d9ff"]
# ๐ธ Ribbon petals
for layer in range(12):
t.color(colors[layer % len(colors)])
for petal in range(10):
angle = petal * 36 + layer * 3
scale = 1 - layer * 0.035
t.penup()
for i in range(61):
a = math.radians(i * 6)
# Elegant curved petal
r = 210 * math.sin(a) * scale
x = r * math.cos(a)
y = r * math.sin(a) * 0.55
rot = math.radians(angle)
X = x * math.cos(rot) - y * math.sin(rot)
Y = x * math.sin(rot) + y * math.cos(rot)
t.goto(X, Y)
if i == 0:
t.pendown()
screen.update()
time.sleep(0.008)
time.sleep(0.04)
# ✨ Center glow
for r in range(35, 2, -3):
t.penup()
t.goto(0, -r)
t.dot(r, "#ffd166")
screen.update()
time.sleep(0.06)
t.penup()
t.goto(0, -7)
t.dot(13, "white")
turtle.done()
Explanation:
1. Import Libraries
import turtleimport mathimport time
- turtle → draws the flower.
- math → calculates angles and curves.
- time → controls animation speed.
2. Create the Screen
screen = turtle.Screen()screen.setup(650, 650)screen.bgcolor("#080014")screen.tracer(0)
- Creates a 650 × 650 window.
- Sets a dark purple background.
- Disables automatic screen updates.
3. Configure the Turtle
t = turtle.Turtle()t.hideturtle()t.speed(0)t.width(2)
- Hides the turtle cursor.
- Sets maximum drawing speed and line thickness.
4. Define Neon Colors
colors = ["#ff4d8d", "#ff8fab", "#c77dff", "#7b2cff", "#00d9ff"]
- Defines five pink, purple, and cyan shades for the petals.
5. Create Flower Layers
for layer in range(12): t.color(colors[layer % len(colors)])
- Creates 12 overlapping layers.
- Repeats the neon colors across layers.
6. Create 10 Petals
for petal in range(10): angle = petal * 36 + layer * 3 scale = 1 - layer * 0.035
- Creates 10 petals per layer.
- Rotates each petal by 36°.
- Gradually reduces the size of inner layers.
7. Generate Petal Points
for i in range(61): a = math.radians(i * 6)
- Generates 61 points for each curve.
- Converts the angle into radians.
8. Calculate the Petal Shape
r = 210 * math.sin(a) * scale
- Calculates the changing radius.
- Creates an elegant curved petal shape.
9. Calculate Coordinates
x = r * math.cos(a)y = r * math.sin(a) * 0.55
- Calculates horizontal and vertical positions.
- The 0.55 factor makes the petal flatter.
10. Rotate the Petals
rot = math.radians(angle)X = x * math.cos(rot) - y * math.sin(rot)Y = x * math.sin(rot) + y * math.cos(rot)
- Converts the rotation angle into radians.
- Rotates each point to position the petals around the flower.
11. Draw the Petals
t.goto(X, Y)if i == 0: t.pendown()
- Moves the turtle to each calculated point.
- Starts drawing from the first point and connects the curve.
12. Animate the Drawing
screen.update()time.sleep(0.008)
- Updates the screen.
- Adds a small delay for live animation.
time.sleep(0.04)
- Pauses briefly after each petal.
13. Create the Center Glow
for r in range(35, 2, -3): t.penup() t.goto(0, -r) t.dot(r, "#ffd166")
- Draws decreasing golden circles.
- Creates a glowing center effect.
14. Add the White Core
t.penup()t.goto(0, -7)t.dot(13, "white")
- Adds a bright white highlight at the center.
15. Finish the Drawing
turtle.done()
- Keeps the Turtle window open.

0 Comments:
Post a Comment