Code:
import turtle, time
s = turtle.Screen()
s.bgcolor("#bdefff")
s.setup(700, 700)
s.tracer(0)
t = turtle.Turtle()
t.speed(0)
t.hideturtle()
t.width(5)
def circle(x, y, r, fill):
t.penup()
t.goto(x, y-r)
t.setheading(0)
t.color("black", fill)
t.pendown()
t.begin_fill()
t.circle(r)
t.end_fill()
s.update()
time.sleep(0.35) # ๐ข Slow drawing
# ๐ผ Head
circle(0, 100, 150, "white")
# ๐ Ears
circle(-105, 215, 45, "black")
circle(105, 215, 45, "black")
# ๐️ Eye patches
circle(-58, 115, 42, "black")
circle(58, 115, 42, "black")
# ๐ Eyes
circle(-58, 120, 13, "white")
circle(58, 120, 13, "white")
# ✨ Pupils
circle(-58, 120, 6, "black")
circle(58, 120, 6, "black")
# ๐ Nose
circle(0, 62, 17, "black")
# ๐ Smile
t.penup()
t.goto(-32, 52)
t.setheading(-60)
t.pendown()
t.color("black")
t.width(5)
t.circle(32, 120)
# ๐ Cheeks
circle(-92, 55, 13, "#ff8fab")
circle(92, 55, 13, "#ff8fab")
# ๐ผ Body
circle(0, -115, 105, "black")
# ๐ค Belly
circle(0, -105, 68, "white")
# ๐พ Arms
circle(-105, -105, 32, "black")
circle(105, -105, 32, "black")
# ๐ฆถ Feet
circle(-55, -235, 38, "black")
circle(55, -235, 38, "black")
s.mainloop()
Explanation:
1. Import Libraries
import turtle, time
turtle → Used to create the Panda drawing.
time → Used to add a delay between drawing each part.
2. Create the Turtle Screen
s = turtle.Screen()
Creates the Turtle graphics window.
s is used to control the screen.
s.bgcolor("#bdefff")
Sets the background color to a light blue.
#bdefff is a hexadecimal color code.
s.setup(700, 700)
Sets the window size to 700 × 700 pixels.
s.tracer(0)
Turns off Turtle's automatic screen animation.
The drawing will only appear when s.update() is called.
3. Create the Turtle Pen
t = turtle.Turtle()
Creates a Turtle object named t.
This turtle performs all the drawing.
t.speed(0)
Sets the turtle's drawing speed to the fastest setting.
t.hideturtle()
Hides the turtle cursor from the screen.
t.width(5)
Sets the pen thickness to 5.
4. Create a Reusable Circle Function
def circle(x, y, r, fill):
Defines a function named circle().
It accepts four parameters:
x → horizontal position
y → vertical position
r → radius of the circle
fill → fill color
This function is the main shortcut used to create all the Panda's circular parts.
Move to the Circle's Starting Point
t.penup()
Lifts the pen.
Moving the turtle won't draw a line.
t.goto(x, y-r)
Moves the turtle to the bottom of the circle.
y-r calculates the starting point using the radius.
t.setheading(0)
Points the turtle toward the right.
This is necessary for t.circle() to draw consistently.
5. Set Outline and Fill Color
t.color("black", fill)
Sets:
Pen/outline color → black
Fill color → value stored in fill
For example:
circle(0, 100, 150, "white")
creates a white circle with a black outline.
6. Fill the Circle
t.pendown()
Places the pen down so drawing can begin.
t.begin_fill()
Starts recording the area that will be filled.
t.circle(r)
Draws a circle with radius r.
t.end_fill()
Fills the circle using the specified fill color.
7. Update and Slow Down the Drawing
s.update()
Manually refreshes the screen.
This is required because s.tracer(0) disabled automatic updates.
time.sleep(0.35)
Pauses the program for 0.35 seconds.
This makes the Panda appear to be drawn step-by-step instead of instantly.
๐ผ 8. Draw the Head
circle(0, 100, 150, "white")
Center of head → (0, 100)
Radius → 150
Fill → white
Creates the Panda's large white head.
๐ 9. Draw the Ears
circle(-105, 215, 45, "black")
Creates the left ear.
-105 moves it toward the left.
215 places it near the top.
Radius is 45.
Fill is black.
circle(105, 215, 45, "black")
Creates the right ear.
Positive 105 moves it toward the right.
๐️ 10. Draw the Eye Patches
circle(-58, 115, 42, "black")
Creates the left black eye patch.
circle(58, 115, 42, "black")
Creates the right black eye patch.
These large black circles give the Panda its characteristic eye markings.
๐ 11. Draw the White Eyes
circle(-58, 120, 13, "white")
Creates the left white eyeball.
circle(58, 120, 13, "white")
Creates the right white eyeball.
The smaller white circles are placed on top of the black eye patches.
⚫ 12. Draw the Pupils
circle(-58, 120, 6, "black")
Creates the left black pupil.
circle(58, 120, 6, "black")
Creates the right black pupil.
Because these are smaller circles placed over the white eyes, they create the Panda's pupils.
๐ 13. Draw the Nose
circle(0, 62, 17, "black")
Creates the Panda's nose.
x = 0 keeps it centered.
y = 62 places it below the eyes.
Radius is 17.
๐ 14. Draw the Smile
t.penup()
Stops the turtle from drawing while moving.
t.goto(-32, 52)
Moves to the starting point of the smile.
t.setheading(-60)
Rotates the turtle to an angle of -60°.
t.pendown()
Starts drawing.
t.color("black")
Sets the smile color to black.
t.width(5)
Makes the smile line 5 pixels thick.
t.circle(32, 120)
Draws an arc, rather than a complete circle.
Radius → 32
Arc angle → 120°
This creates the curved smile.
๐ 15. Draw the Cheeks
circle(-92, 55, 13, "#ff8fab")
Creates the left pink cheek.
#ff8fab is a pink color.
circle(92, 55, 13, "#ff8fab")
Creates the right pink cheek.
๐ผ 16. Draw the Body
circle(0, -115, 105, "black")
Creates the Panda's black body.
Center → (0, -115)
Radius → 105.
๐ค 17. Draw the Belly
circle(0, -105, 68, "white")
Creates a smaller white circle on the body.
This becomes the Panda's belly.
Because it is drawn after the body, it appears on top of the black body.
๐ค 18. Draw the Arms
circle(-105, -105, 32, "black")
Creates the left arm.
circle(105, -105, 32, "black")
Creates the right arm.
The negative and positive x values position the arms symmetrically.
๐พ 19. Draw the Feet
circle(-55, -235, 38, "black")
Creates the left foot.
circle(55, -235, 38, "black")
Creates the right foot.
๐ฅ️ 20. Keep the Window Open
s.mainloop()
Keeps the Turtle window open.
Prevents the program from immediately closing after the drawing is complete.

0 Comments:
Post a Comment