Python Game for Kids: Pikachu Drawing with Turtle Graphics

Introduction:

In this lesson, we are going to be using Python Turtle to draw a picture of Pikachu! This is a fun way to review basic commands using Turtle, so let’s get started!

Table Of Content:

Who is this Project For?

This is an intermediate-level project for those who are new to Python. At this point, you should already know the basics of using Turtle, such as drawing shapes, controlling the pen with fill and colour change commands, and controlling the pen’s location in the window. Basic Python experience is needed as well, such as knowing booleans, creating classes, and defining functions. These will be the core concepts used in this project. Note that this project is also quite long, but although the project as a whole may take some time to complete the steps and concepts are quite simple and easy to follow.

 

What Will We Learn?

This project focuses on using pen commands and functions to draw the final image. By the end of the project, you will be able to confidently use these commands to create images in the Turtle window.

 

Features to Consider:

  • The project should be able to create a clear image
  • The drawing should use multiple colours
  • he drawing should be done in a reasonable amount of time

Main Steps:

This project can be broken down into 6 main steps:

  1. Setup Turtle and create Initial Functions
  2. Define facial features
  3. Draw the body
  4. Draw head and upper body
  5. Draw left hand and leg
  6. Draw right hand and leg
  7. Draw the tail
  8. Set the locations of the facial features
  9. Define the main function

Step 1: Setup Turtle and Create Initial Functions:

First, we’ll start by importing the turtle library. We do this by typing

import turtle 


Next, we will need to define our position function. To do this we will set up a function with our X and Y coordinates and use these to define the turtle’s position. We’ll type:

def getPosition(x, y): 
  turtle.setx(x) 
  turtle.sety(y)
  print(x, y)

Now that we have our getPosition function defined, we can go ahead and begin coding the other main functions for the drawing. But first, we’ll need to create a class for our Pikachu. In this case, we’ll be creating a class called “Pikachu” that will contain all of the functions we’ll use to draw the image.

Underneath, we’ll define two of our most important functions: _init_ (self) and noTrace_goto. The code for these functions will look like this:

class Pikachu: 
  def init (self):
    self.t = turtle.Turtle() 
    t = self.t
    t.pensize(3) 
    t.speed(9) 
    t.ondrag(getPosition)
  def noTrace_goto(self, x, y):
    self.t.penup()
    self.t.goto(x, y) 
    self.t.pendown()

Notice that the self function starts by defining the turtle, setting the pen size to 3 and the speed to 9, and also gets the turtle’s position. They are the basic setup lines of code that will allow the image to be drawn as efficiently as possible and sets the line size to the proper width. The noTrace_goto function is a function that will pick up the pen, move it to the desired location, then set the pendown to draw again.

This function will be used all throughout the project.

 

Step 2: Define facial features

Now that the initial functions have been created it’s time to move on to define the facial features. This will include the code for the eyes, mouth, nose, cheeks, and ears. We’ll start by creating the code for the left eye. This will be made up of two circles inside of one another and then a smaller white one to act as are flection in the eye. We’ll start by creating the function itself and setting up the turtle. To do this we will type:

def leftEye(self, x, y): 
  self.noTrace_goto(x, y)
  t = self.t 

Next, we’ll set the turtle’s heading to 0 by using the turtle.seth() function.

Hint: This will set the turtle’s orientation to a specific angle, in this case, we’re using 0.

Now we’ll begin the circles. Start by choosing a dark grey colour for the eye, then begin filling in a circle with a radius of 22 pixels. Once this is done we will end the fill to complete the circle. When complete, the code will look like this:

t.seth(0)
t.fillcolor('#333333')
t.begin_fill()
t.circle(22)
t.end_fill()

Now we’ll make the other two smaller circles. For the first, we’ll make the turtle move 10 pixels up, before setting the colour to 0 and drawing a circle with a radius of10 pixels. This will use the same basic


code as the first circle. Once this is done, we’ll make the third circle. The code is the same, but we will move the turtle to (x+6, y+22) and the colour of the circle will be white to act as a highlight.

Hint: You can change the colour hex codes used in the code if you want to customize the colours of your Pikachu!

After these steps are complete the code will be:

self.noTrace_goto(x, y + 10) 
t.fillcolor('#000000')
t.begin_fill()
t.circle(10)
t.end_fill()
self.noTrace_goto(x + 6, y + 22)
t.fillcolor('#ffffff')
t.begin_fill()
t.circle(10)
t.end_fill()

Now it’s time to define the right eye. The code for the first two circles will be the exact same as the left eye. The third circle will also be very similar, except when setting the x and y-coordinates they will be (x-6, y+22). Once this function has been created it should look like this:

def rightEye(self, x, y):
  self.noTrace_goto(x, y)
  t = self.t t.seth(0)
  t.fillcolor('#333333')
  t.begin_fill()
  t.circle(22)
  t.end_fill()
  self.noTrace_goto(x, y + 10)
  t.fillcolor('#000000')
  t.begin_fill()
  t.circle(10)
  t.end_fill()
  self.noTrace_goto(x - 6, y + 22)
  t.fillcolor('#ffffff')
  t.begin_fill()
  t.circle(10)
  t.end_fill()

Note: We have written a line of code saying that t = self.t. This line simply defines the turtle and will allow us to draw with it.

Now we’ll write the code for our Pikachu’s mouth. We’ll start by creating a mouth function and setting the turtle’s location and colour. In this case, we’re setting the colour to a dark red colour. After this is complete the code will look like this and we’re ready to begin!

def mouth(self, x, y):
  self.noTrace_goto(x, y)
  t = self.t
  t.fillcolor('#88141D')
  t.begin_fill()

First, we’ll start by creating two lists. In this case, we’ve called them l1 and l2. Then, we’ll set the turtle’s heading to 190 degrees and create a variable with a value of 0.7. This variable will be used to control how far the turtle moves. Then, we’ll create a for loop to move the turtle right 3 degrees and forward by the number of pixels in the variable we just created. It will then add the position to the “l1” list using the append function, and the loop will repeat 28 times. The code will look like this:

l1 = []
l2 = []
t.seth(190)
a = 0.7
for i in range(28):
  a += 0.1
  t.right(3)
  t.fd(a)
  l1.append(t.position())

Then we’ll set the heading to 10 degrees again and repeat the loop, this time appending the values to the “l2” list instead. Once this is done the inner mouth code will look like this:

self.noTrace_goto(x, y)
t.seth(10)
a = 0.7
for i in range(28):
  a += 0.1
  t.left(3)
  t.fd(a)
  l2.append(t.position())

Now it’s time to move on and create the code for the upper lip, tongue, and nose. For the upper lip, we will start by setting the turtle’s heading to 10 degrees, then will draw two half-circles, turning the turtle left by 180 degrees after the first circle. One will be (-50, 15) and the other will be (-50, 40). These will create one of the bumps for the upper lip. Then we’ll set the turtle’s heading to 233degrees and make two more half-circles, one with (-50, 55) and the other being(50, 12.1).

Hint: When using the circle method, we can type turtle.circle(100, 180). In this example, the circle will have a radius of 100 pixels and will only draw 180 degrees of the circle (a half-circle).

Then we will end the fill using the end_fill method. Once the upper lip code is complete it should look like this:

t.seth(10)
t.circle(50, 15)
t.left(180)
t.circle(-50, 15)
t.circle(-50, 40)
t.seth(233)
t.circle(-50, 55)
t.left(180)
t.circle(50, 12.1) 
t.end_fill()

For the tongue ,we will start by making the turtle go to (15, 54) and set the fill colour to light pink. Then we’ll begin filling and set the pen’s heading to 145 degrees before making a half-circle with measurements of (40, 86). Then we will lift the turtle’s pen and use two for loops to decide where the pen should go. For reversed values in the l1 list, the turtle will go to the values of position 1and position 2 + 1.5. The second for loop will be the same, except the values are taken from the l2 list instead. Then, the turtle will place the pen down and end the fill. Once the tongue code is complete it will look like this:

self.noTrace_goto(17, 54)
t.fillcolor('#DD716F')
t.begin_fill()
t.seth(145)
t.circle(40, 86)
t.penup()
for pos in reversed(l1[:20]):
  t.goto(pos[0], pos[1] + 1.5)
for pos in l2[:20]:
  t.goto(pos[0], pos[1] + 1.5)
t.pendown()
t.end_fill()

The nose has a very simple code. All we will do is go to (-17, 94), set the pen’s heading to 8degrees, then move forward 4 pixels and backward 8. The code for this step will be:

self.noTrace_goto(-17, 94)
t.seth(8)
t.fd(4)
t.back(8)

Now that the mouth and eyes are complete it’s time to add the code for the cheeks. We’ll start by creating the leftCheek function and defining the turtle and its location with the goto(x, y) function. Then, we’ll set the turtle’s heading to300, the colour to dark pink, and begin filling. We will use for loops and if statements to draw the cheeks. We’ll start by creating a variable (in this case we’ve titled it “a”), and setting its value to 2.3. Then, we create a loop to run 120 times. Inside, we’ll check to see if the number of times the loop has run is between 0 and 30 or 60 and 90. If so, “a” is equal to itself minus 0.5.The turtle will then turn left 3 degrees and move forward by “a” pixels. Otherwise, “a” is equal to itself plus 0.5 and will turn left 3 degrees and move forward by a value of “a”. After this is done, we will end the fill and the code will look like this:

def rightCheek(self, x, y):
  t = self.t
  self.noTrace_goto(x, y)
  t.seth(60)
  t.fillcolor('#DD4D28')
  t.begin_fill()
  a = 2.3
  for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
      a -= 0.05
      t.lt(3)
      t.fd(a)
    else:
      a += 0.05
      t.lt(3)
      t.fd(a)
  t.end_fill()

The right cheek will use the same code, but at the beginning, the heading will be set to 60instead, so the code will be

t.seth(60)

Finally, we’re onto making the coloured tips of Pikachu’s ears. These are the last facial features to code for this step. As usual, we will start by defining the function and turtle, and set the turtle coordinates to x and y. Then, the pen colour will be set to black and we will begin filling. The code for this section will look like this:

def colorLeftEar(self, x, y):
  t = self.t
  self.noTrace_goto(x, y)
  t.fillcolor('#000000')
  t.begin_fill()
  t.seth(330) 
  t.circle(100, 35)
  t.seth(219)
  t.circle(-300, 19)
  t.seth(110)
  t.circle(-30, 50) 
  t.circle(-300, 10)
  t.end_fill()

Notice how we've set the headings to 330, 219, and 110 in between making the circles, and we've made four partial circles with different radii. The code for the right ear is very similar and follows the same steps but with different coordinates and values for the circle radius. The code for the right ear is:

def colorRightEar(self, x, y): 
  t = self.t
  self.noTrace_goto(x, y)
  t.fillcolor('#000000')
  t.begin_fill()
  t.seth(300)
  t.circle(-100, 30)
  t.seth(35)
  t.circle(300, 15)
  t.circle(30, 50)
  t.seth(190)
  t.circle(300, 17)
  t.end_fill()

And now we’re done with the facial features and are ready to move on to creating the body!

Step 3: Draw the body:

This step consists of multiple components:

  • Draw head and upper body
  • Draw left hand and leg
  • Draw right hand and leg

Let’s start by creating the head and upper body. We’ll start by creating a body function, then we’ll define the turtle, set the pen colour to a bright yellow, and begin filling. The code for the right side of the face and right ear will look like this:

def body(self):
  t = self.tbody
  t.fillcolor('#F6D02F')
  t.begin_fill()
# right face t.penup() t.circle(130, 40) t.pendown() t.circle(100, 105) t.left(180) t.circle(-100, 5)
  t.circle(30, 50)
  t.seth(190)
  t.circle(300, 36)

Notice that we have used a variety of partial circles to create the ear shape and the side of the head, and the turtle’s heading is adjusted every time. Next, we’ll create the rest of the upper body. This is done by simply setting the turtle’s heading to 150 and making a 70-degree circle with a radius of 150. The code for this step will be:

t.seth(150)
t.circle(150, 70)

Now it’s time to code the left side of the head and the left ear. Like the right ear, this is made up of many semicircles and we need to make sure to adjust the turtle’s pen angle in between each circle. The code for the right side of the face is:

t.circle(300, 40)
t.circle(30, 50)
t.seth(20)
t.circle(300, 36)
t.seth(240)
t.circle(105, 95)
t.left(180)
t.circle(-105, 5)

Now that the face and head are complete it’s time to move on to the left side of the body. We’ll start with the left arm and leg. Like the rest of the body, this step consists mainly of making many semicircles to act as curves for the body. The left arm will have circles with large radii to make the main arm, then the fingers will be much smaller with sharper angles. We will be using thet.seth() function to adjust the pen angle after every circle. Once the left side of the body is complete, the code will look like this:

t.seth(210)
t.circle(500, 18)
t.seth(200)
t.fd(10)
t.seth(280)
t.fd(7)
t.seth(210)
t.fd(10)
t.seth(300)
t.circle(10, 80)
t.seth(220)
t.fd(10)
t.seth(300)
t.circle(10, 80)
t.seth(240)
t.fd(12)
t.seth(0)
t.fd(13)
t.seth(240)
t.circle(10, 70)
t.seth(10)
t.circle(10, 70)
t.seth(10)
t.circle(300, 18)
t.seth(75)
t.circle(500, 8)
t.left(180)
t.circle(-500, 15)
t.seth(250)
t.circle(100, 65)
t.seth(320)
t.circle(100, 5)
t.left(180)
t.circle(-100, 5)
t.seth(220)
t.circle(200, 20)
t.circle(20, 70)
t.seth(60)
t.circle(-100, 20)
t.left(180)
t.circle(100, 20)
t.seth(300)
t.circle(10, 70)
t.seth(60)
t.circle(-100, 20)
t.left(180)
t.circle(100, 20)
t.seth(10)
t.circle(100, 60)

Now that the left side of the body is complete we’ll add the horizontal line to transition from the left to the right side of the body. This will be done by simply setting the heading to 0 and making a circle with the measurements (-700, 10), like so:

t.seth(0)
t.circle(-700, 10)

Finally, it’s time to code the right side of the body, including the arm and leg. As with the left side, the right side is primarily made up of semicircles and angle changes, with some forward movement for straight lines. You may notice that some of the code is very similar between the two sides, with the angles changed slightly or measurements adjusted. This simplifies the coding process because once you understand the basics the rest becomes much quicker to code. Follow this code below to draw the right side of Pikachu’s body:

t.seth(290)
t.circle(100, 55)
t.circle(10, 50)
t.seth(120)
t.circle(100, 20)
t.left(180)
t.circle(-100, 20)
t.seth(0)
t.circle(10, 50)
t.seth(110)
t.circle(100, 20)
t.left(180)
t.circle(-100, 20)
t.seth(30)
t.circle(20, 50)
t.seth(100)
t.circle(100, 40)
#Right Body 
t.seth(200)
t.circle(-100, 5)
t.left(180)
t.circle(100, 5)
t.left(30)
t.circle(100, 75)
t.right(15)
t.circle(-300, 21)
t.left(180)
t.circle(300, 3)
#Right Arm
t.seth(43)
t.circle(200, 60)
t.right(10)
t.fd(10)
t.circle(5, 160)
t.seth(90)
t.circle(5, 160)
t.seth(90)
t.fd(10)
t.seth(90)
t.circle(5, 180)
t.fd(10)
t.left(180)
t.left(20)
t.fd(10)
t.circle(5, 170)
t.fd(10)
t.seth(240)
t.circle(50, 30)
t.end_fill()

Now that the body is complete, it’s time to move on to the final details– the fingers. To make the fingers we’ll start by using our noTrace function to move the turtle to(130, 125). Then, we’ll set the angle to -20 degrees, move forward 5 pixels, and draw a small semicircle with the measurements (-5, 160) before removing 5more pixels forward. This will draw the thumb. Next, we’ll add two more fingers by going to (166, 130). We will set the turtle’s heading to -90 degrees, move forward 3 pixels, and make another small circle with the measurements (-4,180). We will repeat this code once more to make the next finger, and once this step is complete the code should look like this:

self.noTrace_goto(130, 125)
t.seth(-20)
t.f	d(5)
t.circle(-5, 160)
t.fd(5)
self.noTrace_goto(166, 130)
t.seth(-90)
t.fd(3)
t.circle(-4, 180)
t.fd(3)
t.seth(-90)
t.fd(3)
t.circle(-4, 180)
t.fd(3)

Step 4: Draw the tail

Now that Pikachu’s body and facial features have been completed, it’s time to draw the tail. Because it is shaped like a zig-zag, this section of code will have many more forward movements than the previous sections. We’ll start by moving the turtle to (168, 134). Then, we’ll select the same bright yellow colour that we used on the body for the tail and begin the pen’s filling. Afterward, we will adjust the pen’s angle and move forward. These steps will repeat many times until they reach Pikachu’s arm. Then, the tail will curve around the arm before continuing the zigzag shape. For the measurements and angle changes needed to draw the tail correctly, refer to this code:

self.noTrace_goto(168, 134)
t.fillcolor('#F6D02F')
t.begin_fill()
t.seth(40)
t.fd(200)
t.seth(-80)
t.fd(150)
t.seth(210)
t.fd(150)
t.left(90)
t.fd(100)
t.right(95)
t.fd(100)
t.left(110)
t.fd(70)
t.right(110)
t.fd(80)
t.left(110)
t.fd(30)
t.right(110)
t.fd(32)
t.right(106)
t.circle(100, 25)
t.right(15)
t.circle(-300, 2)
t.seth(30)
t.fd(40)
t.left(100)
t.fd(70)
t.right(100)
t.fd(80)
t.left(100)
t.fd(46)
t.seth(66)
t.circle(200, 38)
t.right(10)
t.fd(10)
t.end_fill()

And now that the tail is complete, it’s time to add the coloured pattern at the bottom. To do this, we’ll start by setting the pen colour to a dark brown colour. Then we’ll set the heading to 30, move forward 40, set the heading to 100, and move forward 40 again. This will make one of the pattern’s spikes. Then, we will repeat this pattern two more times for a total of three spikes. After this is done, the pen will follow the pre-drawn tail to close up the shape before filling it in. After the tail pattern is complete the code will look like this:

t.fillcolor('#923E24')
self.noTrace_goto(126.82, -156.84)
t.begin_fill()
t.seth(30)
t.fd(40)
t.left(100)
t.fd(40)
t.seth(-30)
t.fd(30)
t.left(140)
t.fd(20)
t.right(150)
t.fd(20)
t.left(150)
t.fd(20)
t.right(150)
t.fd(20)
t.left(130)
t.fd(18)
t.seth(-45)
t.fd(67)
t.right(110)
t.fd(80)
t.left(110)
t.fd(30)
t.right(110)
t.fd(32)
t.right(106)
t.circle(100, 25)
t.right(15)
t.circle(-300, 2)
t.end_fill()

Step 5: Set the locations of the facial features

Now that the body is complete it’s time to set locations for all of the facial features. You may have noticed that throughout the code we have not referred to specific coordinates often. In this step we will be defining the pen’s starting point for each step. The mouth will start at (-5, 25), the cheeks will be at (-126, 32) and (107, 63), the ears will be at (-250, 100) and (140, 270), and the eyes will be positioned at (-85, 90) and (50,110). Finally, we will hide the turtle so that it is not visible once the image is complete. After this step is complete the code will be:

self.mouth(-5, 25)
self.leftCheek(-126, 32)
self.rightCheek(107, 63)
self.colorLeftEar(-250, 100)
self.colorRightEar(140, 270)
self.leftEye(-85, 90)
self.rightEye(50, 110)
t.hideturtle()

Step 6: Define the main function

Finally, all that’s left is to define our start and main functions. The start function is created by simply setting t to self.body() like so:

def start(self):
  t =self.body()

Now all that’s left is to make and run the main function. To do this, create a new function, and underneath set the turtle screen size to 800x600 pixels. We will title the project “Pikachu”. Then, we will start the Pikachu function we created earlier and set up the turtle main loop as well. Finally, we will call the main function to run the entire program. After this step is complete the project is finished and the code should look like this:

def main():
  turtle.screensize(800, 600)
  turtle.title('Pikachu')
  pikachu = Pikachu()
  pikachu.start()
  turtle.mainloop()
main()

And now we’re done! Feel free to test your code and see how it works. If you’re stuck or have any issues with your code, try reviewing it to see if you’ve made any mistakes, or check out the code mentioned above as a reference.

Keep Learning: Python for Kids

Geekedu offers Python coding for kids that will give kids and teenagers a head start in Python coding. Outside of Python, we also teach coding courses for kids 8-18 in a variety of languages like Java, C++, Animation and more.

Check out our online courses for kids, or contact our admissions team to learn which course is best for your student!

Kelsey

Geekedu is an expert in Coding and Math learning. Our goal is to inspire and empower youth to use their knowledge of technology to become the influencers, inventors and innovators of the future.

Sign up and get a 60-minute free assessment class

Book A FREE Trial