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
import turtle
n = 10
pen = turtle.Turtle()
for i in range (n * 3 ):
pen.forward(i * 10 )
pen.right( 120 )
turtle.done()
|
Output:
Last Updated :
20 Aug, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...