How to Draw Shapes in Python Using Turtle?

Draw shapes in Python turtle

Are you trying to Draw Shapes in a Python Turtle? If yes, then this article will help you out drawing shapes in Python using Turtle; stay with us 😇.

Python is used to develop various applications, including gaming applications, web applications, text processing, image processing, enterprise-level applications, robotics, and a variety of other tasks.

In Python, Turtle is a pre-installed library used to create geometrical shapes and pictures. It provides the users with a virtual canvas. There is an onscreen pen in a turtle shape that is used for the drawing of shapes. Due to this turtle-shaped pen, this library is named Turtle. 🐢

You might already know that this module offers turtle graphic primitives in both procedure-oriented and object-oriented ways. So, it doesn’t matter if the shapes are simple or complex; you can easily draw this using the Turtle module. It is a well-known library for introducing programming to beginners because, using this module, one can easily understand the code syntax, and the output would be in the form of shapes.

 

 

Methods Used to Draw Shapes in Python Turtle

Before going into the details of how to draw shapes in Python using turtle, you should learn and understand its necessary methods. It will help you draw different kinds of images and geometrical shapes. 

The following methods are discussed below:

  1. Forward (distance): It will help the turtle in moving forward ⏩ 
  2. Backward (distance): It will help the turtle in moving backward 🔙
  3. Pensize (width of a line): It will set the thickness of a line. The default pen size for each shape is 1 pixel if you pass it null.
  4. speed(): The speed() function will help you in increasing or decrease turtle speed while drawing images and shapes on the screen. You can set the speed between 0 to 10. 
    1. 0 means the fastest speed. It means no animation is applied.
    2. 1 means the slowest speed.
    3. 3 means slow speed.
    4. 6 means normal speed.
    5. 10 means fast speed.
  5. left (angle): This method helps the turtle in moving in an anticlockwise direction.
  6. Right (angle): This method helps the turtle in moving in a clockwise direction.
  7. Circle (radius, extent, and steps): This method will help in drawing a circle ⭕ It has the following parameters which define:
  8. Radius: It defines the circle radius
  9. Extent: It defines a number to extend the pixel or point of a circle.
  10. Steps: It defines the integer value for controlling the points in the circle.
  11. Pendown(): This method will help in putting down the pen, and it leaves a trail when the turtle starts moving.
  12. Penup (): This method will help the turtle in moving to a specified place without leaving or drawing a trail on the screen.

 

 

How to Draw Shapes in Python Using Turtle?

We’ve discussed the different yet useful functions of Turtle; now let’s implement those to draw shapes in Python Turtle.

 

a. Draw a Triangle Shape in Python Using Turtle

Let’s draw a triangle in Python using Turtle.

 

Code

# import everything from turtle

from turtle import *




# darw a trianle

shape("turtle")

pensize(4)

circle(80, 360, 3)

 

Output

Darw a trianlge in python using turtle

 

b. Draw a Circle Shape in Python Using Turtle

Let’s draw a circle in the Python Turtle.

 

Code

# import everything from turtle

from turtle import *




# draw a circle

shape("turtle")

pensize()

circle(90)

 

Output

Darw a circle in python using turtle

 

Draw a Rectangle Shape in Python Using Turtle

Let’s draw a rectangle in the Python Turtle.

 

Code

# import everything from turtle

from turtle import *




# draw a rectangle

shape("turtle")

pensize(3)




for j in range(3):

    forward(100)

    left(90)

    forward(50)

    left(90)

 

Output

Darw a rectanlge in python using turtle

 

Draw a Pentagon Shape in Python Using Turtle

Let’s draw a pentagon in a Python Turtle.

 

Code

# import everything from turtle

from turtle import *




# draw a pentagon

shape("turtle")

pensize(4)




for j in range(5):

    forward(90)

    left(72)

 

Output 

Darw a Pentagon in python using turtle

 

Draw Hexagon Shape in Python Using Turtle

Let’s draw a hexagon in Python Turtle.

 

Code

# import everything from turtle

from turtle import *




# draw a hexagon

shape("turtle")

pensize(3)




for i in range(6):

    forward(90)

    left(60)

 

Output

Darw a Hexagon in python using turtle

 

Draw Complex Shapes in Python Using Turtle

Let’s draw a complex shape in a Python Turtle.

 

Code

# import turtle

import turtle




def draw_dream():

    window = turtle.Screen()

# applying background colour 

   window.bgcolor("black")

    draw_Scarlett()

    window.exitonclick()

    

def draw_Scarlett():

    b = turtle.Turtle()

# pen shape will be a turtle

    b.shape("turtle")

# applying colour to the shape

    b.color("white")

    draw_head(b)

    draw_body(b)

    draw_arm(b)

    draw_leg1(b)

    draw_leg2(b)

    

def draw_head(b):

    b.circle(60)

    b.speed(2)

    b.right(60)




def draw_body(b):

    n = 0

    while n < 3:

        b.forward(150)

        b.right(120)

        b.speed(2)

        n += 1

        

def draw_arm(b):

# turtle will move forward

    b.forward(60)

    b.left(60)

    b.forward(60)

# turtle will move backward

    b.backward(60)

# turtle will move in clockwise direction

    b.right(60)

    b.backward(60)

    b.right(60)

    b.forward(60)

    b.right(60)

    b.forward(60)

    b.backward(60)

# turtle will move forward in anti clockwise direction

    b.left(60)

    b.forward(90)

    

def draw_leg1(b):

    b.left(120)

    b.forward(40)

    b.right(120)

    b.forward(120)

    draw_foot1(b)

    

def draw_leg2(b):

# applying colour to the leg 2

    b.color("white")

    b.right(180)

    b.forward(120)

    b.right(60)

    b.forward(70)

    b.right(60)

    b.forward(120)

    draw_foot2(b)

    

def draw_foot1(b):

# applying colour to the foot 1

    b.color("white")

    n = 0

    while n < 4:

        b.forward(20)

        b.right(90)

        n += 1




def draw_foot2(b):

# applying colour to the foot 2

    b.color("white")

    n = 0

    while n < 4:

        b.forward(20)

        b.left(90)

        n += 1




draw_dream()

 

Output

Darw complex shapes in python using turtle

 

 

Conclusion

To conclude the article on how to draw shapes in a Python Turtle, we’ve discussed how one can use various functions to draw shapes in a python turtle. Further, we’ve drawn amazing shapes like a triangle, rectangles, circles, pentagons, hexagons, and complex shapes using the Python Turtle. 

Let’s have a quick recap of the topics discussed in this article

  1. What is a python turtle?
  2. What are the useful functions to draw Shapes in Python Turtle?
  3. How to Draw Shapes in a Python Turtle?

Hope you find this article helpful. Do share your experience with the python turtle library in the comments below 👇. And Don’t forget to share this article with your friends. Help them in learning creative shapes using the python turtle module. 😍

 

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts
Total
0
Share