leafleafleafDocy banner shape 01Docy banner shape 02Man illustrationFlower illustration

Python turtle module example: draw Peppa Pig (middle)

Estimated reading: 2 minutes 15 views

Following the previous tutorial, we continued to draw Peppa Pig.

cheek() function

Next, we define the cheek() function, which draws a red circle to represent the blush. The cheek() function code is shown below.

def cheek():           
    penup()
    goto(80,10)
    setheading(0)
    color((255,155,192))
    pendown()   
    begin_fill()
    circle(30)
    end_fill()

Call this function to see its drawing effect, as shown in Figure 1.

Python cheek() function
figure 1

mouth() function

Next we define the mouth() function, which is to draw a red arc to represent the mouth. The code for the mouth() function is shown below.

def mouth():        
    penup()
    goto(-20,30)
    color(239,69,19)
    pendown()
    setheading(-80)
    circle(35,120)

Call this function to see the drawing effect, as shown in Figure 2.


figure 2

body() function

Next, we define the body() function, which is used to draw the body. The code for the body() function is shown below.

def body():
     color("red",(255,99,71))
     #The curve on the left side of the body
     penup()
     goto(-32,-8)
     pendown()
     begin_fill()
     setheading(-130)
     circle(100,10)
     circle(300,30)
     #body bottom
     setheading(0)
     forward(230)
     #The curve on the right side of the body
     setheading(90)
     circle(300,30)
     circle(100,3)
     color((255,155,192),(255,100,100))
     #Draw the chin on the face to avoid covering it when filling
     setheading(-135)
     circle(-80,63)
     circle(-150,24)
     end_fill()

Call this function to see the drawing effect, as shown in Figure 3.

Python body() function
image 3

hands() function

Next, we define the hands() function to draw hands. The code for the hands() function is shown below.

def hands():
     color((255,155,192))
     # middle finger of left hand
     penup()
     goto(-56,-45)
     pendown()
     setheading(-160)
     circle(300,15)
     # Represent the other two fingers of the left hand through an arc
     penup()
     setheading(90)
     forward(15)
     setheading(0)
     pendown()
     setheading(-10)
     circle(-20,90)
     # middle finger of right hand
     penup()
     setheading(90)
     forward(30)
     setheading(0)
     forward(237)
     pendown()
     setheading(-20)
     circle(-300,15)
     # Represent the other two fingers by an arc
     penup()
     setheading(90)
     forward(20)
     setheading(0)
     pendown()
     setheading(-170)
     circle(20,90)

Call this function to see the drawing effect, as shown in Figure 4.

Python hands() function

Leave a Comment

CONTENTS