Introduction to Turtle programming

Turtle is a pre-installed library in Python that is similar to the virtual canvas that we can draw pictures and attractive shapes. It provides the onscreen pen that we can use for drawing.

The turtle Library is primarily designed to introduce children to the world of programming. With the help of Turtle’s library, new programmers can get an idea of how we can do programming with Python in a fun and interactive way.

It is beneficial to the children and for the experienced programmer because it allows designing unique shapes, attractive pictures, and various games. We can also design the mini-games and animation. In the upcoming section, we will learn to various functionalities of the turtle library.

The turtle is a built-in library so we don’t need to install it separately. We just need to import the library into our Python environment.

The Python turtle library consists of all the important methods and functions that we will need to create our designs and images. Import the turtle library using the following command.

” import turtle “

Programming with turtle

We can customize the pen-like turtle and its environment. Turtle can be moved in four directions.

  • Forward

  • Backward

  • Left

  • Right

We can draw any shape using the turtle, such as a rectangle, triangle, square, and many more. But, we need to take care of coordinate while drawing the rectangle because all four sides are not equal. Once we draw the rectangle, we can even try creating other polygons by increasing the number of sides.

The speed of the turtle can be changed. Generally, it moves at a moderate sped over the screen but we can increase and decrease its speed.

Colors make an image or shapes very attractive. We can fill shapes with various colors. Let’s understand the following example to add color to the drawings.

By default, the turtle points to the right on the screen. Sometimes, we require moving the turtle to the other side of the screen itself. To accomplish this, we can use the pen-up method. The pen down function uses to start drawing again.