Drawing a star in Python using turtle Graphics

Drawing a star in Python using turtle Graphics

Install turtle package using below command:

pip import turtle

Below is the code to generate a star

#import turtle package
import turtle

#list with colors is declared
color = ['blue','orange','purple','red','yellow']

#window created to draw a star graphic
window = turtle.Screen()

#decide the screen
star = turtle.Turtle()

#set the pen size
star.pensize(25)

#draw 5 overlapping lines of star using the for loop below
for line in range(5): 
    #setting the color by pulling each color from the list - color
    star.pencolor(color[line])
    star.forward(200)
    star.right(288)

turtle.done()

The output is as below:

Post a Comment

0 Comments