Code:
import turtle
import time
screen = turtle.Screen()
screen.setup(600, 600)
screen.bgcolor("#050510")
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
# Face
t.penup()
t.goto(0, -180)
t.color("#ffd600")
t.fillcolor("#ffd600")
t.begin_fill()
t.circle(180)
t.end_fill()
screen.update()
time.sleep(0.3)
# Eyes
for x in [-65, 65]:
t.penup()
t.goto(x, 45)
t.dot(35, "#151515")
screen.update()
time.sleep(0.2)
# Smile
t.penup()
t.goto(-85, -30)
t.setheading(-60)
t.color("#151515")
t.width(10)
t.pendown()
for _ in range(60):
t.forward(3)
t.left(2)
screen.update()
time.sleep(0.015)
# Small highlights
for x in [-58, 72]:
t.penup()
t.goto(x, 55)
t.dot(8, "white")
turtle.done()
Explanation:
1. Import Libraries
import turtle
import time
turtle → Used for drawing.
time → Adds animation delays.
2. Create the Screen
screen = turtle.Screen()
screen.setup(600, 600)
screen.bgcolor("#050510")
Creates the Turtle window.
Sets the size to 600 × 600.
Gives it a dark background.
3. Create the Turtle
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
Creates the drawing turtle.
Hides the turtle cursor.
Sets the fastest drawing speed.
4. Draw the Face
t.penup()
t.goto(0, -180)
Lifts the pen.
Moves to the starting position.
t.color("#ffd600")
t.fillcolor("#ffd600")
Sets the outline color.
Sets the face fill color to yellow.
t.begin_fill()
t.circle(180)
t.end_fill()
Starts filling the shape.
Draws a circle with radius 180.
Fills it with yellow.
5. Animate the Face
screen.update()
time.sleep(0.3)
Updates the screen.
Pauses briefly.
6. Draw the Eyes
for x in [-65, 65]:
Loops through two X positions.
Creates the left and right eyes.
t.penup()
t.goto(x, 45)
Moves to each eye position without drawing.
t.dot(35, "#151515")
Draws a dark circular eye.
screen.update()
time.sleep(0.2)
Updates the screen.
Adds an animation delay.
7. Draw the Smile
t.penup()
t.goto(-85, -30)
Moves to the starting point of the smile.
t.setheading(-60)
Sets the initial drawing direction.
t.color("#151515")
t.width(10)
t.pendown()
Sets a dark color.
Makes the smile thick.
Starts drawing.
8. Create the Curved Smile
for _ in range(60):
Repeats the drawing movement 60 times.
t.forward(3)
t.left(2)
Moves forward.
Turns slightly left.
Together, these create the curved smile.
screen.update()
time.sleep(0.015)
Updates the animation.
Adds a tiny delay.
9. Add Eye Highlights
for x in [-58, 72]:
Selects positions for both eye highlights.
t.penup()
t.goto(x, 55)
Moves to each highlight position.
t.dot(8, "white")
Adds a small white dot.
Creates a shiny eye effect.
10. Finish
turtle.done()
Keeps the Turtle window open.
Ends the drawing.

0 Comments:
Post a Comment