Draw Indian Flag Using Python

Published by StudyMuch on

Draw Indian Flag Using Python

Draw Indian Flag Using Python’s Turtle Graphics

The Indian national flag is a testament to unity, diversity, and the vibrant culture of India. The dynamic tricolor, with its saffron, white, and green hues, along with the iconic Ashoka Chakra, proudly represents the nation. In this tutorial, we will delve into the world of Python and use its Turtle graphics library to create a stunning representation of the Indian flag, (Draw Indian Flag Using Python).

Step 1: Setting the Canvas with Turtle Graphics

Before we start drawing, make sure you have Python installed on your system. If not, you can download it from the official website (https://www.python.org/downloads/). Python’s turtle graphics library is a powerful tool for creating intricate visualizations, making it perfect for our endeavor.

Indian Flag with Python Code

Step 2: Drawing the Tricolor Background

The Indian flag is known for its distinct tricolor composition. To capture this, let’s start by drawing the saffron and green rectangles.

# Import the turtle library 
import turtle
from turtle import*

# Set up the canvas  
screen = turtle.Screen()
t = turtle.Turtle()
speed(5)

# Orange Rectangle  
#white rectangle  
def draw_orange_rectangle():
    # initially penup()  
    t.penup()
    t.goto(-200, 125)
    t.pendown()
    t.color("orange")
    t.begin_fill()
    t.forward(400)
    t.right(90)
    t.forward(84)
    t.right(90)
    t.forward(400)
    t.end_fill()
    t.left(90)
    t.forward(84)

# Draw Green Rectangle  
def draw_green_rectangle():
    t.color("green")
    t.begin_fill()
    t.forward(84)
    t.left(90)
    t.forward(400)
    t.left(90)
    t.forward(84)
    t.end_fill()



Step 3: Incorporating the Ashoka Chakra

The Ashoka Chakra, with its 24 spokes, is a symbol of progress and dynamic change. Let’s add the Chakra and its spokes to our design.

# Big Blue Circle  
def big_blue_circle():
    t.penup()
    t.goto(35, 0)
    t.pendown()
    t.color("navy")
    t.begin_fill()
    t.circle(35)
    t.end_fill()
# Big White Circle  

def big_white_circle():
    t.penup()
    t.goto(30, 0)
    t.pendown()
    t.color("white")
    t.begin_fill()
    t.circle(30)
    t.end_fill()

#Mini Blue Circles of Flag  
def mini_blue():
    t.penup()
    t.goto(-27, -4)
    t.pendown()
    t.color("navy")
    for i in range(24):
    t.begin_fill()
    t.circle(2)
    t.end_fill()
    t.penup()
    t.forward(7)
    t.right(15)
    t.pendown()

# Small Blue Circle  
def draw_small_blue_circle():
    t.color("navy")
    t.penup()
    t.goto(10, 0)
    t.pendown()
    t.begin_fill()
    t.circle(10)
    t.end_fill()

#The spokes of India Flag  
def flag_spokes():
    t.penup()
    t.goto(0, 0)
    t.pendown()
    t.pensize(1)
    for i in range(24):
    t.forward(30)
    t.backward(30)
    t.left(15)

#for stick of the flag  
def flag_stick():
    t.color("Brown")
    t.pensize(10)
    t.penup()
    t.goto(-200,125)
    t.right(180)
    t.pendown()
    t.forward(800)
    draw_orange_rectangle()
    draw_green_rectangle()
    big_blue_circle()
    big_white_circle()
    mini_blue()
    draw_small_blue_circle()
    flag_spokes()
    flag_stick()
    turtle.done()

Conclusion;

With the magic of Python’s turtle graphics library, we’ve successfully brought the beauty of the Indian flag to life on our canvas. The intricate details, from the tricolor stripes to the Ashoka Chakra, stand as a testament to both the creativity of Python and the rich symbolism of the Indian flag. As you admire your creation, remember the significance of the flag and the unity it represents. Happy coding and exploring the art of digital design! (Draw Indian Flag Using Python). So, in this article you have learn to create Indian Flag with Python Code, and here we have provide you full code to create the India Flag.

Learn More;


1 Comment

tlovertonet · May 5, 2024 at 7:37 pm

It is really a great and useful piece of information. I?¦m glad that you just shared this helpful info with us. Please stay us informed like this. Thanks for sharing.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *