Open In App

Python – Draw Star Using Turtle Graphics

In this article, we will learn how to make a Star using Turtle Graphics in Python. For that let’s first know what is Turtle Graphics.

Turtle graphics

Turtle is a Python feature like a drawing board, which let us command a turtle to draw all over it! We can use many turtle functions which can move the turtle around. Turtle comes into the turtle library. The turtle module can be used in both object-oriented and procedure-oriented ways.



Some commonly used methods are:

Approach 

import turtle
ws=turtle.Screen()

A screen like this will appear:-



Below is the python implementation of the above approach.

First way :




# import for turtle
import turtle
 
# Starting a Working Screen
ws = turtle.Screen()
 
# initializing a turtle instance
geekyTurtle = turtle.Turtle()
 
# executing loop 5 times for a star
for i in range(5):
 
        # moving turtle 100 units forward
        geekyTurtle.forward(100)
 
        # rotating turtle 144 degree right
        geekyTurtle.right(144)

 
 

Output:

Turtle Making A Star

Alternate Approach:




#import turtle
import turtle
 
# set screen
Screen = turtle.Turtle()
 
# decide colors
cir= ['red','green','blue','yellow','purple']
 
# decide pensize
turtle.pensize(4)
 
# Draw star pattern
turtle.penup()
turtle.setpos(-90,30)
turtle.pendown()
for i in range(5):
    turtle.pencolor(cir[i])
    turtle.forward(200)
    turtle.right(144)
 
turtle.penup()
turtle.setpos(80,-140)
turtle.pendown()
 
# choose pen color
turtle.pencolor("Black")
turtle.done()

Output:-

 


Article Tags :