Open In App

Draw Shape inside Shape in Python Using Turtle

Prerequisites: Turtle Programming in Python

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:

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



Triangle inside Triangle

Follow the below steps:

Below is the python implementation.




# import the turtle modules
import turtle
 
 
# define the function
# for triangle
def form_tri(side):
    for i in range(3):
        my_pen.fd(side)
        my_pen.left(120)
        side -= 10
 
         
# 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 = 300
for i in range(10):
    form_tri(side)
    side -= 30

Output : 

Square inside Square

Follow the below steps: 

Below is the python implementation. 




# 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 : 

Hexagon inside Hexagon

Follow the below steps: 

Below is the python implementation. 




# import the turtle modules
import turtle
 
 
# define the function
# for hexagon
def form_hex(side):
    for i in range(6):
        my_pen.fd(side)
        my_pen.left(300)
        side -= 2
 
 
# 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 sizes
side = 120
 
for i in range(5):
    form_hex(side)
    side -= 12

Output :


Article Tags :