Draw Polygons using Python..๐Ÿ

Draw Polygons using Python..๐Ÿ

ยท

2 min read

Hello People,

In this Blog article, we will learn how to Draw a set of polygons. We will see the implementation in Python.

Check out the Repository in python . Drop a star if you find it useful !!!

We are going to learn how to draw a set of polygons using Python Turtle Graphics by making use of functions of the turtle module.

Turtle is an inbuilt Python library that enables users to create simple graphics and shapes by providing them with a virtual canvas. Hereโ€™s my code that creates a set of polygons using a turtle.

Video on YouTube:

Code:

# import turtle module
import turtle as t

tu = t.Turtle()

# set starting coordinates.
tu.penup()
tu.goto(-50, 100)
tu.pendown()

# loop for drawing polygons
num_sides = 3

while num_sides != 11:
    for _ in range(num_sides):
        angle = 360 / num_sides
        tu.forward(100)
        tu.right(angle)
    num_sides += 1

# Screen() method in the turtle module is used to get the screen open.
screen = t.Screen()

# exit the screen after a single left click.
screen.exitonclick()

Output:

v2 thumb.PNG

Thank you.

See you in my next Blog article, Take care!!

Dhruvin Gajjar.

TheCreators

Resources:

ย