Draw Spiraling Triangle using Turtle in Python

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 Triangle of size n:  

  • Import turtle and create a turtle instance.
  • Using for loop(i = 0 to i< n * 3) and repeat below step
    • turtle.forward(i * 10).
    • turtle.right(120).
  • Close the turtle instance.

Below is the implementation:

Python3



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.