In this article, we are going to learn how to draw the shape of a Diamond using turtle graphics in Python.
Turtle graphics:
- forward(length): moves the pen in the forward direction by x unit.
- right(angle): rotate the pen in the clockwise direction by an angle x.
- left(angle): rotate the pen in the anticlockwise direction by an angle x.
Approach:
- Import the turtle modules.
- Define an instance for the turtle.
- First, make the bigger triangle
- Then make three lines inside the bigger triangle
- Then make 4 small triangles
- Then make one line above these four triangles
Below is the Python implementation of the above approach:
Python3
import turtle
pen = turtle.Turtle()
wn = turtle.Screen()
pen.left( 60 )
pen.forward( 200 )
pen.left( 120 )
pen.forward( 200 )
pen.left( 120 )
pen.forward( 200 )
pen.left( 150 )
pen.forward( 174 )
pen.backward( 174 )
pen.left( 16.5 )
pen.forward( 180 )
pen.backward( 180 )
pen.right( 31.5 )
pen.forward( 180 )
pen.right( 75 )
pen.forward( 53 )
pen.left( 120 )
pen.forward( 50 )
pen.left( 120 )
pen.forward( 50 )
pen.right( 120 )
pen.forward( 50 )
pen.left( 120 )
pen.forward( 50 )
pen.right( 120 )
pen.forward( 50 )
pen.left( 120 )
pen.forward( 50 )
pen.right( 120 )
pen.forward( 50 )
pen.left( 120 )
pen.forward( 50 )
pen.left( 180 )
pen.forward( 50 )
pen.left( 300 )
pen.forward( 160 )
|
Output:
