Cat using Python Turtle

Cat face using Python Turtle

Introduction

To draw Cat using Python Turtle, we will utilize the turtle package. It is a Python GUI package that can be used to draw anything, including characters, cartoons, shapes, and other objects.

If you’re new to Python, drawing a cat can be tricky, but don’t worry, I’ll explain everything and supply you with the code for this application.

More articles about the python turtle and its projects can be found on our website. You can use our website’s search box or go to our Homepage.

Steps of Creating Cat using Python Turtle :

Step 1: Import The Turtle and Math Library

import turtle
import math

Step 2: Select the Background Color

window = turtle.Screen()
window.bgcolor("yellow")
#Bg color is use to set the background color

Step 3: Declare the Cursor Size and Speed

cursor = turtle.Turtle() # Cursor
cursor.shape("turtle")
cursor.color("black")
cursor.speed(3)
cursor.pensize(10)

Step 4: Creating Function to set X and Y Position

def movePen(cursor, x, y):
  cursor.penup()
  #Penup() ensures that the moving object you've created does not draw anything on the window. 
  cursor.setposition(x, y)
   #setpos (also can be used as .setposition()) can be used to set a position for turtle.
  cursor.pendown()
  #pendown() tell the turtle to leave ink on the screen as it moves or not to leave ink.

def movePenX(cursor, x):
  cursor.penup()
  cursor.setx(x) 
#setx() can be used to change the turtle’s positing along the x-axis (horizontally) while vertical position is untouched. 
  cursor.pendown()

def movePenY(cursor, y):
  cursor.penup()
  cursor.sety(y)
  cursor.pendown()

def positionAlongCircle(x, y, radius, angle):
  radians = math.radians(angle)
  return [x + (radius*math.sin(radians)),
            y + (radius*math.cos(radians))]
#This function is use for to draw ears whiskers around the circle

Step 5: Draw the head

movePenY(cursor, -150)
cursor.circle(150)

Step 6: Draw the Nose

noseMouthOffset = -15

movePenY(cursor, -20 + noseMouthOffset)
cursor.circle(20)

Step 7: Draw the mouth

movePen(cursor, -100, -20 + noseMouthOffset)
cursor.right(90)
cursor.circle(50, 180)
cursor.left(180)
cursor.circle(50, 180)

Step 8: Draw the eyes

eyeSpacingX = 30
eyePosY = 40
eyeRadius = 30

Step 9: Right eye

movePen(cursor, eyeSpacingX, eyePosY)
cursor.right(180)
cursor.circle(eyeRadius, -180)

Step 10: Left eye

movePen(cursor, -eyeSpacingX, eyePosY)
cursor.circle(eyeRadius, 180)

Step 11: Draw the tongue

movePen(cursor, -20, -60 + noseMouthOffset)
cursor.circle(20, 180)

Step 12: Draw the ears

# Right ear

earBeginAngle = 25
earSize = 85
earWidth = 22
positionA =  (0, 0, 150, earBeginAngle)
movePen(cursor, positionA[0], positionA[1])

positionB = positionAlongCircle(0, 0, 150 + earSize, earBeginAngle + earWidth)
cursor.setposition(positionB[0], positionB[1])

positionC = positionAlongCircle(0, 0, 150, earBeginAngle + earWidth * 2)
cursor.setposition(positionC[0], positionC[1])

# Left ear

positionA = positionAlongCircle(0, 0, 150, -earBeginAngle)
movePen(cursor, positionA[0], positionA[1])

positionB = positionAlongCircle(0, 0, 150 + earSize, -earBeginAngle + -earWidth)
cursor.setposition(positionB[0], positionB[1])

positionC = positionAlongCircle(0, 0, 150, -earBeginAngle + -earWidth * 2)
cursor.setposition(positionC[0], positionC[1])

Step 13: Draw the Whiskers

whiskerLength = 180

# Right whiskers

movePen(cursor, 50, -15)
cursor.setheading(0)
cursor.forward(whiskerLength)

movePen(cursor, 50, 0)
cursor.left(5)
cursor.forward(whiskerLength)

# Left whiskers

movePen(cursor, -50, -15)
cursor.setheading(180)
cursor.forward(whiskerLength)

movePen(cursor, -50, 0)
cursor.left(-5)
cursor.forward(whiskerLength)

window.exitonclick()
#exitonclick() was created to end program.

Complete Code to draw Cat using Python Turtle

import turtle
import math

window = turtle.Screen()
window.bgcolor("gray")

cursor = turtle.Turtle() # Cursor
cursor.shape("turtle")
cursor.color("black")
cursor.speed(3)
cursor.pensize(10)


def movePen(cursor, x, y):
  cursor.penup()
  cursor.setposition(x, y)
  cursor.pendown()

def movePenX(cursor, x):
  cursor.penup()
  cursor.setx(x)
  cursor.pendown()

def movePenY(cursor, y):
  cursor.penup()
  cursor.sety(y)
  cursor.pendown()

def positionAlongCircle(x, y, radius, angle):
  radians = math.radians(angle)
  return [x + (radius*math.sin(radians)),
            y + (radius*math.cos(radians))]

# Draw the head

movePenY(cursor, -150)
cursor.circle(150)

# Draw the nose

noseMouthOffset = -15

movePenY(cursor, -20 + noseMouthOffset)
cursor.circle(20)

# Draw the mouth

movePen(cursor, -100, -20 + noseMouthOffset)
cursor.right(90)
cursor.circle(50, 180)
cursor.left(180)
cursor.circle(50, 180)

# Draw the eyes

eyeSpacingX = 30
eyePosY = 40
eyeRadius = 30

# Right eye

movePen(cursor, eyeSpacingX, eyePosY)
cursor.right(180)
cursor.circle(eyeRadius, -180)

# Left eye

movePen(cursor, -eyeSpacingX, eyePosY)
cursor.circle(eyeRadius, 180)

# Draw the tongue

movePen(cursor, -20, -60 + noseMouthOffset)
cursor.circle(20, 180)

# Draw the ears

# Right ear

earBeginAngle = 25
earSize = 85
earWidth = 22
positionA = positionAlongCircle(0, 0, 150, earBeginAngle)
movePen(cursor, positionA[0], positionA[1])

positionB = positionAlongCircle(0, 0, 150 + earSize, earBeginAngle + earWidth)
cursor.setposition(positionB[0], positionB[1])

positionC = positionAlongCircle(0, 0, 150, earBeginAngle + earWidth * 2)
cursor.setposition(positionC[0], positionC[1])

# Left ear

positionA = positionAlongCircle(0, 0, 150, -earBeginAngle)
movePen(cursor, positionA[0], positionA[1])

positionB = positionAlongCircle(0, 0, 150 + earSize, -earBeginAngle + -earWidth)
cursor.setposition(positionB[0], positionB[1])

positionC = positionAlongCircle(0, 0, 150, -earBeginAngle + -earWidth * 2)
cursor.setposition(positionC[0], positionC[1])

# Whiskers

whiskerLength = 180

# Right whiskers

movePen(cursor, 50, -15)
cursor.setheading(0)
cursor.forward(whiskerLength)

movePen(cursor, 50, 0)
cursor.left(5)
cursor.forward(whiskerLength)

# Left whiskers

movePen(cursor, -50, -15)
cursor.setheading(180)
cursor.forward(whiskerLength)

movePen(cursor, -50, 0)
cursor.left(-5)
cursor.forward(whiskerLength)

window.exitonclick()

Output :

output Cat face using Python Turtle
Output

Also Read:

Share:
Avatar of Vatsal Rakholiya

Author: Vatsal Rakholiya