Turtle in Python

Swati Tripathi
Analytics Vidhya
Published in
3 min readDec 7, 2020

Learn about the turtle library in python that you can you use for vector graphics and create beautiful patterns and shapes.

Turtle graphics is inspired by the real turtles and their movements!

About Turtle:

Turtle in Python allows you to draw things like shapes and pattern. It is a library in Python that you can import and then use it to draw whatever you want. In this, you will see an onscreen pointer shaped cursor that you can command to move left, right, back or forward to draw something for you and this pointer shaped cursor is known as “turtle”.

Teaching about turtle to kids is a fun way to introduce them to programming. With the help of this, you create some cool mini-games or animations including snake game.

A little bit history:

This concept of turtle graphics was used in Logo programming language which was developed by Wally Feurzig and Seymour Papert in 1966. “Logo” is a general-purpose educational programming language which was made to teach programming concepts that were related to Lisp, a functional programming language.

Using Turtle:

Let’s see some statements(written in bold below) to start experimenting with turtle graphics in python:

To import turtle library and to use its feature: import turtle

To create a screen where you will draw: myscreen = turtle.Screen()

To change the color of the screen: myscreen = turtle.bgcolor(“light blue”)

To give a title to your screen: myscreen = turtle.title(“My Drawing Board”)

To create a turtle cursor object that will draw for you: tortoise=turtle.Turtle()

To move turtle cursor right by 90 distance: tortoise = turtle.right(90)

To move turtle backward with 120 distance: tortoise = turtle.backward(120)

Note myscreen and tortoise are variable names and you can use any other words instead of them. It's completely your choice. Moreover, there are lots of other inbuilt functions in this turtle library which you can check out in this documentation.

Creating Square using turtle library

code for creating square using turtle library as shown on the right side

Another example of creating a pattern using turtle:

If trying out the above code don’t forget to import turtle first.

Let’s create a beautiful pattern using turtle

Now since you have got introduced to turtle let’s see a small beautiful pattern that you can create. Try out the code as shown in the image below:

Try this code out!
The output of the above code

For more information about the turtle, I would recommend to check out this.

The end. Hope this article helped you :)

--

--

Swati Tripathi
Analytics Vidhya

I believe everyone should hustle hard to make a positive impact!