Open In App
Related Articles

Draw Spiraling Polygon using Turtle in Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Prerequisite: Python Turtle Basic

Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle, methods defined in the turtle module and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen). To move turtle(pen) there are some functions i.e forward(), backward(), etc.

Approach to draw a Spiraling Polygon of the given sides and of size n:  

  • Import turtle and create a turtle instance.
  • Set sides = 5, sides of the polygon.
  • Using for loop(i = 0 to i < n * sides) and repeat below step
    • turtle.forward(i  * 10).
    • turtle.right(360 / sides).
  • Close the turtle instance.

Below is the implementation:

Python3

# importing turtle module 
import turtle 
  
# number of side
sides=5
  
# size
n = 7
  
# creating instance of turtle 
pen = turtle.Turtle() 
  
# loop to draw a side 
for i in range(n*sides): 
      
    # drawing side of 
    # length i*10 
    pen.forward(i * 10
      
    # changing direction of pen 
    # by 360/sides degree in clockwise 
    pen.right(360 / sides)
      
# closing the instance 
turtle.done() 

                    

Output:


Last Updated : 18 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads