Introduction
A turtle is a Python tool that functions similarly to a drawing board, allowing us to tell a turtle to draw all over it! Many turtle functions can be used to move the turtle around. The turtle explores the turtle library.
The turtle library in Python may be used to create different forms on a canvas. The programmer can direct a pen in a particular direction by specifying its heading and distance. In this article, we'll look at using the Turtle module to create Star. Steps to draw a Polygon turtle.
Steps to Draw a Star Using Turtle in Python
Approach 1 - Creating Simple Star
For creating a simple star:
- Import a turtle and create an object from it.
- Get a screen board for the turtle to sketch on.
- Iterate the loop five times if you need five edges in the star.
- Move forward turtle x length and turn it 144 degrees; it depends on you.
- It will give you the output of a perfect star.
Code
# draw any polygon in turtle
# import turtle
import turtle
# Screen board for the turtle to sketch on.
screenForSketching = turtle.Screen()
# creating turtle object
ob = turtle.Turtle()
# Iterate the loop five times for a star
for i in range(5):
# moving turtle 100 units forward
ob.forward(100)
# rotating turtle 144 degree right
ob.right(144)
Output

Approach 2 - Creating a Colorful Star
For creating a colorful star:
- Import a turtle and create an object from it.
- Get a screen board for the turtle to sketch on.
- Select the color of the turtle.
- Iterate the loop five times if you need five edges in the Star.
- Move forward turtle x length and turn it 144 degrees. It depends on you.
- It will give you a perfect Star.
- Now fill in the color in the Star.
Code
# draw any polygon in turtle
# import turtle
import turtle
# function to draw
# colored Star
def create_color_star():
# size of Star
sigeOfStar = 100
# Assign colour to the edges.
turtle.color("orange")
# Set the width
turtle.width(4)
# Give angle to form Star
assine_angle = 120
# Fill the colour as of your choice.
turtle.fillcolor("green")
turtle.begin_fill()
# Create a Star
for side in range(5):
turtle.forward(sigeOfStar)
turtle.right(angle)
turtle.forward(sigeOfStar)
turtle.right(72 - angle)
# fill color
turtle.end_fill()
# Driver code
create_color_star()Output

You can compile it with online python compiler.



