Draw Indian Flag using Python turtle
Source Code:-
# required module-pip install turtle
import turtle
# inializing a turtle
flag = turtle.Turtle()
turtle.bgcolor("black")
# for creating first reactangle
flag.begin_fill()
flag.fillcolor("orange")
flag.forward(500)
flag.right(90)
flag.forward(100)
flag.right(90)
flag.forward(500)
flag.right(90)
flag.forward(100)
flag.right(90)
flag.end_fill()
# for second rectangle
flag.right(90)
flag.forward(100)
flag.begin_fill()
flag.fillcolor("white")
flag.forward(100)
flag.left(90)
flag.forward(500)
flag.left(90)
flag.forward(100)
flag.left(90)
flag.forward(500)
flag.end_fill()
# for third rectangle
flag.begin_fill()
flag.fillcolor("green")
flag.left(90)
flag.forward(200)
flag.left(90)
flag.forward(500)
flag.left(90)
flag.forward(100)
flag.left(90)
flag.forward(500)
flag.end_fill()
#big blue circle
flag.penup()
flag.setpos(250,-105)
flag.pendown()
flag.begin_fill()
flag.fillcolor("navy")
flag.circle(45)
flag.end_fill()
#big white circle
flag.penup()
flag.setpos(250,-110)
flag.pendown()
flag.begin_fill()
flag.fillcolor("white")
flag.circle(40)
flag.end_fill()
#mini blue circle
flag.penup()
flag.setpos(254,-186)
flag.pendown()
flag.color("navy")
flag.speed(0)
for i in range(24):
flag.begin_fill()
flag.circle(2)
flag.end_fill()
flag.penup()
flag.forward(9.5)
flag.right(15)
#centre blue
flag.penup()
flag.setpos(250,-145)
flag.pendown()
flag.begin_fill()
flag.fillcolor("navy")
flag.circle(5)
flag.end_fill()
#spokes
flag.penup()
flag.setpos(250,-150)
flag.pendown()
flag.pensize(2)
for i in range(24):
flag.forward(40)
flag.backward(40)
flag.left(15)
text = turtle.Turtle()
text.hideturtle()
text.speed(2)
def write(message,pos,color):
x,y = pos
text.color(color)
text.penup()
text.goto(x,y)
text.pendown()
style = ("Calibri", 13,"bold")
text.write(message,font=style)
write('Happy',(-20,-400),'orange')
write('Independence',(-10,-480),'white')
write('Day 2021',(50,-570),'green')
# to hold the
# output window
turtle.done()
Output:-
Wish you all a happy happy independence day 🇮🇳.
Comments
Post a Comment