Draw Peppa Pig with Python Turtle: A Step‑by‑Step Tutorial
This tutorial walks you through creating a complete Peppa Pig illustration using Python's turtle graphics, covering shape analysis, custom drawing functions for each body part, and code snippets that demonstrate arcs, ellipses, and color fills to produce a recognizable cartoon figure.
We first examine the shape of Peppa Pig, which consists of curves: an oval nose, arcs for the head, ears, eyes, cheeks, mouth, body, arms, legs, and a curled tail.
Step 1: Draw arcs and ellipse
Many parts are drawn with arcs. The turtle.circle() function takes radius , extent , and steps . To draw a full circle, pass a single radius or set extent to 360. To draw an arc, specify the desired extent.
<code>import turtle
turtle.pencolor("red")
turtle.setheading(-80)
turtle.circle(100, 120)
</code>Result: a red arc.
Since turtle has no direct ellipse function, we approximate a circle with a regular polygon of many sides, e.g., a 120‑gon.
<code>import turtle
turtle.pendown()
for j in range(120):
turtle.forward(5)
turtle.left(3)
turtle.penup()
</code>By varying the forward distance inside a loop we can create an ellipse with non‑uniform speed.
<code>import turtle
turtle.pendown()
segment = 1
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
segment = segment + 0.2
turtle.left(3)
turtle.forward(segment)
else:
segment = segment - 0.2
turtle.left(3)
turtle.forward(segment)
</code>Step 2: Import turtle module
<code>from turtle import *
</code>Step 3: Set canvas and pen
<code>def setting():
setup(800, 500)
pensize(4)
hideturtle()
colormode(255)
speed(10)
</code>The setting() function configures the drawing window, pen size, hides the turtle cursor, sets RGB color mode, and speeds up drawing.
Step 4: nose() function
<code>def nose():
penup()
goto(-100, 100)
setheading(-30)
color((255,155,192), "pink")
pendown()
begin_fill()
segment = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
segment = segment + 0.08
left(3)
forward(segment)
else:
segment = segment - 0.08
left(3)
forward(segment)
end_fill()
# left nostril
penup()
setheading(90)
forward(25)
setheading(0)
forward(10)
color((255,155,192), (160,82,45))
pendown()
begin_fill()
circle(5)
end_fill()
# right nostril
penup()
setheading(0)
forward(20)
pendown()
begin_fill()
circle(5)
end_fill()
</code>Step 5: head() function
<code>def head():
penup()
goto(-69, 167)
pendown()
color((255,155,192), "pink")
begin_fill()
setheading(180)
circle(300, -30)
circle(100, -60)
circle(80, -100)
circle(150, -20)
circle(60, -95)
setheading(161)
circle(-300, 15)
penup()
goto(-100, 100)
pendown()
setheading(-30)
segment = 0.4
for i in range(60):
if 0 <= i < 30 or 60 <= i < 90:
segment = segment + 0.08
left(3)
forward(segment)
else:
segment = segment - 0.08
left(3)
forward(segment)
end_fill()
</code>Step 6: ears() function
<code>def ears():
color((255,155,192), "pink")
# left ear
penup()
goto(0, 160)
pendown()
begin_fill()
setheading(100)
circle(-50, 50)
circle(-10, 120)
circle(-50, 54)
end_fill()
# right ear
penup()
setheading(90)
forward(-12)
setheading(0)
forward(30)
pendown()
begin_fill()
setheading(100)
circle(-50, 50)
circle(-10, 120)
circle(-50, 56)
end_fill()
</code>Step 7: eyes() function
<code>def eyes():
# left eye white
color((255,155,192), "white")
penup()
setheading(90)
forward(-20)
setheading(0)
forward(-95)
pendown()
begin_fill()
circle(15)
end_fill()
# left pupil
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
# right eye white
color((255,155,192), "white")
penup()
setheading(90)
forward(-25)
setheading(0)
forward(40)
pendown()
begin_fill()
circle(15)
end_fill()
# right pupil
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
</code>Step 8: cheek() function
<code>def cheek():
penup()
goto(80, 10)
setheading(0)
color((255,155,192))
pendown()
begin_fill()
circle(30)
end_fill()
</code>Step 9: mouth() function
<code>def mouth():
penup()
goto(-20, 30)
color(239, 69, 19)
pendown()
setheading(-80)
circle(35, 120)
</code>Step 10: body() function
<code>def body():
color("red", (255,99,71))
penup()
goto(-32, -8)
pendown()
begin_fill()
setheading(-130)
circle(100, 10)
circle(300, 30)
setheading(0)
forward(230)
setheading(90)
circle(300, 30)
circle(100, 3)
color((255,155,192), (255,100,100))
setheading(-135)
circle(-80, 63)
circle(-150, 24)
end_fill()
</code>Step 11: hands() function
<code>def hands():
color((255,155,192))
# left middle finger
penup()
goto(-56, -45)
pendown()
setheading(-160)
circle(300, 15)
# left other two fingers (arc)
penup()
setheading(90)
forward(15)
setheading(0)
pendown()
setheading(-10)
circle(-20, 90)
# right middle finger
penup()
setheading(90)
forward(30)
setheading(0)
forward(237)
pendown()
setheading(-20)
circle(-300, 15)
# right other two fingers (arc)
penup()
setheading(90)
forward(20)
setheading(0)
pendown()
setheading(-170)
circle(20, 90)
</code>Step 12: feet() function
<code>def feet():
# left leg
pensize(10)
color((240,128,128))
penup()
goto(2, -177)
pendown()
setheading(-90)
forward(40)
setheading(-180)
color("black")
pensize(15)
forward(20)
# right leg
pensize(10)
color((240,128,128))
penup()
setheading(90)
forward(40)
setheading(0)
forward(90)
pendown()
setheading(-90)
forward(40)
setheading(-180)
color("black")
pensize(15)
forward(20)
</code>Step 13: tail() function
<code>def tail():
pensize(4)
color((255,155,192))
penup()
goto(148, -155)
pendown()
setheading(0)
# curled tail
circle(70, 20)
circle(10, 330)
circle(70, 30)
</code>Finally, calling all the defined functions in order ( setting() , nose() , head() , ears() , eyes() , cheek() , mouth() , body() , hands() , feet() , tail() ) renders a complete Peppa Pig figure that closely resembles the original cartoon.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.