Square inside Square

Follow the below steps: 

  • Define an instance for turtle.
  • For a square execute a loop 4 times (sides).
  • In every iteration move turtle 90 units forward.
  • This will make up a Square.
  • This is made multiple times to form squares inside squares using a function.

Below is the python implementation. 

Python3




# import the turtle modules
import turtle
 
# define the function
# for square
def form_sq(side):
    for i in range(4):
        my_pen.fd(side)
        my_pen.left(90)
        side -= 5
 
         
# Forming the window screen
tut = turtle.Screen()
tut.bgcolor("green")
tut.title("Turtle")
 
my_pen = turtle.Turtle()
my_pen.color("orange")
 
tut = turtle.Screen()          
 
# for different shapes
side = 200
 
for i in range(10):
    form_sq(side)
    side-= 20


Output : 

Draw Shape inside Shape in Python Using Turtle

Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move the turtle around. Turtle comes in the turtle library. The turtle module can be used in both object-oriented and procedure-oriented ways.

Some of the commonly used methods which are also used here are:

  • forward(length): moves the pen in the forward direction by x unit.
  • backward(length): moves the pen in the backward 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.
  • penup(): stop drawing of the turtle pen.
  • pendown(): start drawing of the turtle pen.

In this article, we will draw various shape inside a similar shape like drawing triangles inside triangle. 

Similar Reads

Triangle inside Triangle

Follow the below steps:...

Square inside Square

...

Hexagon inside Hexagon

Follow the below steps:...