Introduction

Hello my fellow programmers , today we will be talking about an interesting animal, Yeah you guessed it right.TURTLE. Have you heard about the Turtle Module in Python ? It is one of my Favorite modules as it allows you to architect and draw the best designs that you have in your mind. It is very simple and easy to use , yet powerful for designing.

image cannot be displayed

Let’s get Started with Turtle. I suggest you to execute the following Commands IDLE, to understand what it does.

Step 1. Import turtle Module

>>> import turtle

Step 2. Create your own Turtle , Give it any name. It follows your Instructions. I named mine as t.

>>> t = turtle.Turtle()

Note : Immediately after you execute the above command a new Python window will open which has an arrow mark facing to East.

Step 3. Understanding how it all works

From here on observe the Execution of the following code carefully

>>> t.fd(100)  # 1.1
>>> t.fd(200)  # 1.2
>>> t.bk(200)  # 1.3
>>> t.bk(100)
>>> t.bk(100)

C: have you observed what just happenned? You must have cause your smart poeple after all. After you entered Line 1.1, your arow moved along the east direction for 100 units and then when you executed the second line your arrow should have gone 200 units straight right?. Similarly the next three lines move your arrow backwards to 200 , 100 and 100 units respectively. Now you must be Wondering Where your t(the turtle you named) actually is ? The arrow that is gallivanting across your screen is your little turtle , its the default shape that is assigned to your turtle. Execute the below line of code , to see your Turtle.

>>> t.shape(turtle)

Expansions

E:fd → Forward Movement of Turtle / Used to make your Turtle go Forward

E:bk → Backward Movement of Turtle / Used to make your Turtle come Backward

Note : For the Movement of the Turtle we will use only two Basic commands forward and backward. For making it rotate we use the methods lt() and rt() {Left and Right} which take an integer as parameter and that integer parameter specifies the number of degrees your turtle will turn.

>>> t.lt(90)

The Above command instructs the turtle to move in the left direction. 90 degrees. Now let us make this even more simple. Let us assume your turtle is facing the East Direction .

cannot display image

All of the following commands are explained wrt the position of turtle in East Direction.

>>> t.lt(90) #Makes Your Turtle turn to North Direction 
>>> t.rt(90) #Makes Your Turtle turn to South Direction 
>>> t.lt(180) #Makes Your Turtle turn to West Direction 
>>> t.rt(180) #Makes Your Turtle turn to West  Direction 
>>> t.lt(270) #Makes Your Turtle turn to South Direction 
>>> t.rt(270) #Makes Your Turtle turn to North Direction 

Now why dont you try this : Try to move your turtle in a Square. (Hoping that you sincerely tried it) here is how to do it :

Import turtle
t  = turtle.Turtle()
t.fd(100)
t.lt(90)
t.fd(100)
t.lt(90)
t.fd(100)
t.lt(90)
t.fd(100)

above I drew the circle with left command. Do the same with rt() command.

>>> t.circle(50)

If you execute the above command your Turtle draws a circle with radius 50.

Now try this :

from turtle import *
t = Turtle()
for j in range(4):
for i in range(1,11):
		t.circle(i*10)
	t.lt(90)
# wait until it completes , after seeing it youll know.

What you just saw is some really basic thing you could do with Turtle. There’s a lot more to learn about it.

Keep learning and improving.

UNTIL THE NEXT POST, PEACE ;)