How to Create Custom Turtle shapes in Python?

Python's Turtle library is used for generating 2D graphics and animations. It has a very simple interface with help of which we can create shapes and patterns on the screen. It comes with some built-in shapes like squares, circles, triangles etc. However, we can even create our own shapes with the help of Turtle. In this article, we are going to see how to create custom turtle shapes in python.

Before going forward with the creating custom shapes we need to install Turtle on the system and this can be done by simply using the following command ?

pip install turtle

Key Functions for Custom Shapes

We need to see certain functions of Turtle that will be used to help create custom shapes and they are as follows ?

  • register_shape() ? It is used to register a new custom shape in Turtle. It takes in 2 arguments which are the name of the shape (as a string) and a tuple of (x, y) coordinate pairs which represents the vertices of the shape.

  • shape() ? Once a shape has been successfully registered, using the register_shape() method, it can be used as a shape by making use of the shape() functions and has to be given a string argument which is the name of the shape.

  • color() ? This method is only used for setting a colour of figures and it can take in multiple arguments all of which would be related to colours. The arguments could be either the direct name of the colour like red, blue, green etc or hex code of the colour or even the RGB values which would mean 3 arguments in integer format.

In short, register_shape() is used to create and register the shape whereas shape() is used to implement the registered shape.

Creating a Square Shape

We will first see how to create a simple square manually and will require the above-mentioned functions ?

import turtle

# create turtle object
t = turtle.Turtle()

# define shape vertices
square_shape = ((-50, -50), (-50, 50), (50, 50), (50, -50))

# register the shape
turtle.register_shape("square", square_shape)

# use the shape
t.shape("square")
t.color("green")

# This functions is important to keep the turtle window on
turtle.done()

Creating a Star Shape

A star is also a simple shape with points that extend from the centre. It just requires careful declaration of the coordinates whereas the rest of the code would remain the same as above ?

import turtle

t = turtle.Turtle()

star_shape = ((0, 50), (-14, 16), (-50, 16), (-23, -12), (-35, -46),
         (0, -24), (35, -46), (23, -12), (50, 16), (14, 16))

turtle.register_shape("star", star_shape)

t.shape("star")
t.color("green")

turtle.done()

Creating a Hexagon Shape

A hexagon is a 6-sided polygon with 6 angles. It is found in honeycombs or in chemistry benzene rings. Here too, the coordinates needed to be changed and mentioned carefully ?

import turtle

t = turtle.Turtle()
hexagon_shape = ((-50, 0), (-25, 43.3), (25, 43.3), (50, 0), (25, -43.3), (-25, -43.3))

turtle.register_shape("hexagon", hexagon_shape)

t.shape("hexagon")
t.color("red")

turtle.done()

Creating a Cross Shape

The cross symbol is often used by medical facilities like chemists and hospitals. It is also the logo of the red cross society which provides assistance in times of crisis and emergencies ?

import turtle

t = turtle.Turtle()
cross_shape = ((-50, 0), (-15, 0), (-15, -50), (15, -50), (15, 0), (50, 0), (50, 50),
         (15, 50), (15, 100), (-15, 100), (-15, 50), (-50, 50))

turtle.register_shape("cross", cross_shape)

t.shape("cross")
t.color("red")

turtle.done()

Drawing a 3D Cube

Cubes are a 3D shape which consist of 6 square faces. While our screens represent 2D images, we can create a 3D visual effect by drawing three visible faces with different colors ?

import turtle

t = turtle.Turtle()
t.hideturtle()
turtle.tracer(0)

# Draw the front side of the square
t.begin_fill()
t.color("red")
t.goto(100, 0)
t.goto(100, 100)
t.goto(0, 100)
t.goto(0, 0)
t.end_fill()

# Draw the right side of the square
t.begin_fill()
t.color("orange")
t.goto(100, 0)
t.goto(120, 20)
t.goto(120, 120)
t.goto(100, 100)
t.end_fill()

# Draw the top side of the square
t.begin_fill()
t.color("yellow")
t.goto(0, 100)
t.goto(20, 120)
t.goto(120, 120)
t.goto(100, 100)
t.end_fill()

turtle.update()
turtle.done()

Drawing Koch Snowflake

Koch snowflakes are a kind of fractal curve. They are created by using equilateral triangles dividing each of its sides into equal segments and then replacing their middle segments with 2 segments that form an equilateral bump ?

import turtle

t = turtle.Turtle()
# Hide turtle object
t.hideturtle()
turtle.tracer(0)

# Draw the Koch snowflake
def koch_snowflake(length, depth):
    if depth == 0:
        t.forward(length)
    else:
        for angle in [60, -120, 60, 0]:
            koch_snowflake(length / 3, depth - 1)
            t.left(angle)

# Set turtle position and angle
t.penup()
t.goto(-150, 150)
t.pendown()
t.setheading(0)

# Draw the Koch snowflake
t.color("blue")
t.begin_fill()
for i in range(3):
    koch_snowflake(300, 4)
    t.right(120)
t.end_fill()

turtle.done()

Conclusion

The turtle library is really great for creating visual graphics with an added level of personalization to your projects. By using the register_shape() function we can create a shape of any type and use the shape() function to implement the shape. Creating custom shapes is an easy task and only requires a bit of creativity and programming knowledge.

Updated on: 2026-03-27T12:56:59+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements