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
import turtle
sides = 5
n = 7
pen = turtle.Turtle()
for i in range (n * sides):
pen.forward(i * 10 )
pen.right( 360 / sides)
turtle.done()
|
Output:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!