Javatpoint Logo
Javatpoint Logo

Draw Great Indian Flag using Python Code

In this tutorial, we will draw the Indian National Flag using Python's turtle library. Turtle library is a Python library used to create unique graphics, pictures and games in Python.

Python turtle library was developed by Wally Feurzeig, Seymour Parpet and Cynthia Solomon in 1967. It was an original part of the original Logo programming language. This library was initially designed for the children to make some attractive graphics and games. With the help of this library, the developers can create unique shapes, pretty pictures and various games. We can also design the mini-games and animation. We have a complete tutorial on the turtle library. If you want to learn about the turtle library, you can visit our Python turtle library tutorial.

Draw Indian Flag

Let's understand the following steps to create a national flag using turtle library.

Step - 1: Import Turtle library and its Functions

In the first step, we import the turtle library and its built-in function, which will be used in the further program. Here * means importing all the methods that come in the turtle module to create the Flag. Let's see the example -

Example -

Step - 2: Setup the turtle screen

We initialize the turtle screen, first we create the screen instance and then turtle instance. We define the pen speed using the speed() function which takes integer as an argument.

Example -

The speed can be increased if we increase the number.

Step - 3: Create Function of Draw Orange

We create a function to draw an orange rectangle. This function includes the initial object and pen location. We set the position to goto(200, -125). We define the color name as orange. The begin_fill() method will fill the orange color. When the pen is done with the rectangle just move forward to 84 steps which automatically encompasses the whole part of the Flag.

Example -

Step - 4: Create Function to Draw Green Rectangle

Now we draw the green rectangle of the Indian Flag same as the orange rectangle.

Example -

Step - 5: Draw Big Blue Circle

Now we draw the big blue circle in navy color. We set the turtle position to goto(35, 0). The circle radius is kept at 35, and the color is kept navy blue.

Example -

Step - 6: Draw Big White Circle Inside Blue Circle

We set the turtle position at goto(30, 0) and kept a radius of 30, and a white circle is drawn.

Example -

Step - 7: Draw 24 Minicircles

Now we set the turtle position at (-27, -4) and color is navy. We run for loop 24 times to draw 24 minicircles of the Ashok Chakra.

Example -

Step - 8: Draw the Middle Blue Circle

We write the function to draw the innermost navy blue circle of the Indian Flag.

Example -

Step - 9: Drawing the Spokes

Step - 10: Draw the Stick of the Indian Flag

Here we come to the final step; in this set turtle, we have set the turtle position to goto(-200, 125). We increase the pen size to 10 and draw a straight line of the 800 steps, a stick of the Flag.

Example -

Now let's arrange all the created functions and draw the India flag.

Complete Code to Draw Flag

Python Code -

Output:

Draw Great Indian Flag using Python Code

We call all the created functions at the end of the program. It will then draw the Flag according to the speed we have set in the speed() function. You can set the speed as your choice. So finally, we successfully completed the Great Indian Flag drawing using the Python turtle library.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA