Code:
import turtle
import time
screen = turtle.Screen()
screen.setup(650, 650)
screen.bgcolor("white")
screen.tracer(0)
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.width(2)
colors = ["#ff3d00", "#ff6d00", "#ff9800", "#ffc107"]
# รฐลธ”¥ Outer rays
for i in range(48):
angle = i * 7.5
length = 250 if i % 2 == 0 else 215
t.penup()
t.goto(0, 0)
t.setheading(angle)
t.pendown()
t.color(colors[i % len(colors)])
t.forward(length)
screen.update()
time.sleep(0.05) # slower
# รฐลธล¼ Middle rays
for i in range(72):
angle = i * 5
length = 185 if i % 2 == 0 else 145
t.penup()
t.goto(0, 0)
t.setheading(angle)
t.pendown()
t.color("#ff5722" if i % 3 else "#ffd600")
t.forward(length)
screen.update()
time.sleep(0.035) # slower
# รขล¨ Inner rays
for i in range(96):
angle = i * 3.75
t.penup()
t.goto(0, 0)
t.setheading(angle)
t.pendown()
t.color("#ff7043")
t.forward(105)
screen.update()
time.sleep(0.025) # slower
# รฐลธลธ¡ Center
for r in range(28, 2, -2):
t.penup()
t.goto(0, -r)
t.dot(r, "#ffb300")
screen.update()
time.sleep(0.07)
t.penup()
t.goto(0, -9)
t.dot(18, "#fff176")
turtle.done()
Explnation:
1. Import Libraries
import turtleimport time
- turtle → draws the sun rays.
- time → adds animation delays.
2. Create the Screen
screen = turtle.Screen()screen.setup(650, 650)screen.bgcolor("white")screen.tracer(0)
- Creates a 650×650 white canvas.
- tracer(0) allows manual 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 Colors
colors = ["#ff3d00", "#ff6d00", "#ff9800", "#ffc107"]
- Stores orange and yellow shades for the outer rays.
5. Draw Outer Rays
for i in range(48): angle = i * 7.5 length = 250 if i % 2 == 0 else 215
- Draws 48 rays around the center.
- Alternates between two ray lengths.
6. Position and Draw Outer Rays
t.penup()t.goto(0, 0)t.setheading(angle)t.pendown()t.color(colors[i % len(colors)])t.forward(length)
- Starts each ray at the center.
- Sets its direction, selects a color, and draws the line.
7. Animate Outer Rays
screen.update()time.sleep(0.05)
- Refreshes the screen and slows the animation.
8. Draw Middle Rays
for i in range(72): angle = i * 5 length = 185 if i % 2 == 0 else 145
- Draws 72 shorter rays.
- Alternates their lengths to create a layered effect.
t.color("#ff5722" if i % 3 else "#ffd600")
- Uses orange and yellow colors.
9. Draw Inner Rays
for i in range(96): angle = i * 3.75
- Creates 96 closely spaced inner rays.
t.color("#ff7043")t.forward(105)
- Draws short, coral-orange rays.
10. Create the Glowing Center
for r in range(28, 2, -2): t.penup() t.goto(0, -r) t.dot(r, "#ffb300")
- Draws decreasing yellow-orange circles.
- Creates a layered sun-center effect.
11. Add the Final Highlight
t.penup()t.goto(0, -9)t.dot(18, "#fff176")
- Adds a pale-yellow circle at the center.
12. Finish the Drawing
turtle.done()
- Keeps the Turtle window open.

0 Comments:
Post a Comment