The Wayback Machine - https://web.archive.org/web/20241009185811/https://www.geeksforgeeks.org/how-to-make-indian-flag-using-turtle-python/
Open In App

How to Make an Indian Flag in Python

Last Updated : 12 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Here, we will be making “The Great Indian Flag” using Python. Python’s turtle graphics module is built into the Python software installation and is part of the standard library. This means that you don’t need to install anything extra to use the turtle lib. Here, we will be using many turtle functions like begin_fill(), end_fill() to fill color inside the Flag, penup(), pendown(), goto(), etc to reaching the target.

Turtle Graphics

In computer graphics, turtle graphics are vector graphics using a relative cursor upon a Cartesian plane. Python Turtle is a drawing board-like feature that lets us command the turtle and draw using it.

Features of turtle graphics:

  • forward(x): moves the pen in forward direction by x units.
  • backward(x): moves the pen in the backward direction by x units.
  • right(x): rotate the pen in the clockwise direction by an angle x.
  • left(x): rotate the pen in the anticlockwise direction by an angle x.
  • penup(): stop drawing of the turtle pen.
  • pendown(): start drawing of the turtle pen.
  • begin_fill(): starts filling the color inside the shape.
  • fillcolor(“color_name”): sets the color to be filled.
  • end_fill(): stops filling the color.

Approach to Making an Indian Flag in Python Using Turtle

1. Import the turtle modules.

import turtle

2. Get a screen to draw on.

screen = turtle.Screen()

3. Define an instance for turtle(here “t”).

4. For making an Indian Flag let’s divide the process into 4 steps:

  • The rectangle with orange color.
  • Then the middle rectangle.
  • Then the last Green Rectangle.
  • Then Ashoka Chakra inside the middle rectangle.

5. Here dimensions of all three Rectangles are (800 units x 167 units), which makes up dimensions of the flag as (800 units x 501 units).

6. The turtle starts from coordinates (-400, 250).

7. Then from that position it makes the First rectangle of orange color.

8. Then from the ending point of the first rectangle, Turtle makes the Second rectangle of no color.

9. Then the Third green color rectangle is made. Now for Ashoka Chakra, we need to perform a set of operations.

  • A Big Blue circle and a white circle just smaller than blue.
  • Set of small blue circles on the inner lining of a blue and white circle.
  • And finally spokes inside the two blue and white circles starting from the Centre towards the outer direction.

10. Finally, The pride of one’s Nation is ready. 

Code Implementation

Python
import turtle
from turtle import*

#screen for output
screen = turtle.Screen()

# Defining a turtle Instance
t = turtle.Turtle()
speed(0)

# initially penup()
t.penup()
t.goto(-400, 250)
t.pendown()

# Orange Rectangle 
#white rectangle
t.color("orange")
t.begin_fill()
t.forward(800)
t.right(90)
t.forward(167)
t.right(90)
t.forward(800)
t.end_fill()
t.left(90)
t.forward(167)

# Green Rectangle
t.color("green")
t.begin_fill()
t.forward(167)
t.left(90)
t.forward(800)
t.left(90)
t.forward(167)
t.end_fill()

# Big Blue Circle
t.penup()
t.goto(70, 0)
t.pendown()
t.color("navy")
t.begin_fill()
t.circle(70)
t.end_fill()

# Big White Circle
t.penup()
t.goto(60, 0)
t.pendown()
t.color("white")
t.begin_fill()
t.circle(60)
t.end_fill()

# Mini Blue Circles
t.penup()
t.goto(-57, -8)
t.pendown()
t.color("navy")
for i in range(24):
    t.begin_fill()
    t.circle(3)
    t.end_fill()
    t.penup()
    t.forward(15)
    t.right(15)
    t.pendown()
    
# Small Blue Circle
t.penup()
t.goto(20, 0)
t.pendown()
t.begin_fill()
t.circle(20)
t.end_fill()
# Spokes
t.penup()
t.goto(0, 0)
t.pendown()
t.pensize(2)
for i in range(24):
    t.forward(60)
    t.backward(60)
    t.left(15)
    
#to hold the 
#output window
turtle.done()

 Output


 



Previous Article
Next Article

Similar Reads

Program to make Indian Flag in Python | Step by Step
Here, We'll be making Indian Flag in Python using Spyder tool which is a part of Anaconda interface. It is the beginner's practice problem for python programmers. Prerequisite: The only prerequisite for this code is little knowledge of basic python programming. You may install anaconda from here if you don't have any interpreter for python. Approac
4 min read
Draw Indian Flag using matlab
In Digital image processing, a colored image is represented in a 3-Dimensional matrix. Image can be represented in various color models such as RGB (Red, Green, Blue) model, HSV (Hue, Saturation, Value) model, YIQ (Luminance-Inphase Quadrature) model, CMYK (Cyan, Magenta, Yellow, Black) model. Generally, an image is represented in the RGB model. Th
2 min read
Matplotlib.pyplot.flag() in Python
Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.flag() Function The flag() function in pyplot module of matplotlib library is used to set the colormap to "flag". Syntax: matplotlib.pypl
2 min read
Python - Flag None Element Rows in Matrix
Given a Matrix, return True for rows which contain a None Value, else return False. Input : test_list = [[2, 4, None, 3], [3, 4, 1, None], [2, 4, 7, 4], [2, 8, None]] Output : [True, True, False, True] Explanation : 1, 2 and 4th index contain None occurrence. Input : test_list = [[2, 4, None, 3], [3, 4, 1, None], [2, 4, None, 4], [2, 8, None]] Outp
4 min read
What is the use of Python -m flag?
Python, a versatile and widely used programming language, provides a plethora of features and command-line options to facilitate various tasks. One such option that might pique your interest is the -m switch. In this article, we will explore what Python -m is and how it can be used, accompanied by four illustrative code examples. What is Python -m?
2 min read
Draw Sweden Flag using matlab
A colored image can be represented as a 3 order matrix. The first order is for the rows, the second order is for the columns and the third order is for specifying the color of the corresponding pixel. Here we use the RGB color format, so the third order will take 3 values of Red, Green ans Blue respectively. The values of the rows and columns depen
2 min read
How to draw Japan flag using MATLAB
Prerequisite: RGB Image Representation MATLAB, also called Matrix Laboratory, is a numerical computing environment and a platform for programming languages. It was designed and developed by MathWorks. MATLAB is a framework that allows us to perform matrix manipulations, implementing algorithms, plotting functions and data, creating user-interfaces
3 min read
Draw Kuwait Flag using MATLAB
A colored image can be represented as a 3 order matrix. The first order is for the rows, the second order is for the columns and the third order is for specifying the color of the corresponding pixel. Here we use the RGB color format, so the third order will take 3 values of Red, Green ans Blue respectively. The values of the rows and columns depen
2 min read
Draw Sudan Flag using MATLAB
In Digital image processing, a colored image is represented in a 3-Dimensional matrix. Image can be represented in various color models such as RGB (Red, Green, Blue) model, HSV (Hue, Saturation, Value) model, YIQ (Luminance-Inphase Quadrature) model, CMYK (Cyan, Magenta, Yellow, Black) model. Generally, an image is represented in the RGB model. Th
2 min read
PyQtGraph – Setting Window Flag to Plot Window
In this article we will see how we can set window flag to the plot window in the PyQtGraph module. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) and
3 min read
Get Indian Railways Station code Using Python
Web scraping is a technique to fetch data from websites. While surfing on the web, many websites don’t allow the user to save data for personal use. One way is to manually copy-paste the data, which both tedious and time-consuming. Web Scraping is the automation of the data extraction process from websites. This event is done with the help of web s
2 min read
Build GUI Application for Guess Indian State using Tkinter Python
In this article, you will learn to make a GUI game in Python, in which we will be shown a map of Indian states and an input prompt were in the prompt, the user has to enter a state name of India. If the user guessed it correctly, the name would hover over its location on the map. You can also see the score as the title of the input prompt window. M
8 min read
Text transliteration from English to Indian languages - Using indic-transliteration
Transliteration is the process of transferring a word from the alphabet of one language to another. Transliteration helps people pronounce words and names in foreign languages. It is also useful for non-Latin script language speakers to use in their own language, as typing in Latin is more convenient. Examples : Input : namaskaara Output : Translit
2 min read
Using Counter() in Python to find minimum character removal to make two strings anagram
Given two strings in lowercase, the task is to make them Anagram. The only allowed operation is to remove a character from any string. Find minimum number of characters to be deleted to make both the strings anagram? If two strings contains same data set in any order then strings are called Anagrams. Examples: Input : str1 = "bcadeh" str2 = "hea" O
3 min read
Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
Given two strings, find if we can make first string from second by deleting some characters from second and rearranging remaining characters. Examples: Input : s1 = ABHISHEKsinGH : s2 = gfhfBHkooIHnfndSHEKsiAnG Output : Possible Input : s1 = Hello : s2 = dnaKfhelddf Output : Not Possible Input : s1 = GeeksforGeeks : s2 = rteksfoGrdsskGeggehes Outpu
2 min read
Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
Given an array of integers, the task is to find whether it's possible to construct an integer using all the digits of these numbers such that it would be divisible by 3. If it is possible then print "Yes" and if not print "No". Examples: Input : arr[] = {40, 50, 90} Output : Yes We can construct a number which is divisible by 3, for example 945000.
2 min read
Python | Make pair from two list such that elements are not same in pairs
Given two lists, the task is to create pairs of elements (pairs can be repeated) from two list such that elements are not same in pairs. Examples: Input : list1 = [100, 20, 30, 400] list2 = [400, 2, 30] Output: [[100, 400], [100, 2], [100, 30], [20, 400], [20, 2], [20, 30], [30, 400], [30, 2], [400, 2], [400, 30]] Input: list1 = [10,20,30,40] list2
2 min read
Python | Make a list of intervals with sequential numbers
Given a list of sequential numbers, Write a Python program to convert the given list into list of intervals. Examples: Input : [2, 3, 4, 5, 7, 8, 9, 11, 15, 16] Output : [[2, 5], [7, 11], [15, 16]] Input : [1, 2, 3, 6, 7, 8, 9, 10] Output : [[1, 3], [6, 10]] Method #1 : Naive Approach First, we use the brute force approach to Convert list of sequen
3 min read
Python | Make a simple window using kivy
Kivy is a platform independent as it can be run on Android, IOS, linux and Windows etc. Kivy provides you the functionality to write the code for once and run it on different platforms. It is basically used to develop the Android application, but it Does not mean that it can not be used on Desktops applications. Use this command To install kivy: pi
5 min read
How to make a basic Scatterplot using Python-Plotly?
Plotly is a graphing library for making high quality interactive graphs and charts. It is an open source library used for data visualization . This library can be used with three programming languages namely Python, R and Javascript. Using Plotly is very easy and you can make any type of graph using this library. It can generate Statistical charts,
2 min read
How to make calculator using kivy | Python
Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. ???????? Kivy Tutorial - Learn Kivy with Examples. In this article, we will learn how to make a simple calculator
3 min read
Make a violin plot in Python using Matplotlib
Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits like Tkinter, awxPython, etc. Note: For more information, refer to Python Matplotlib – An Overview Wh
3 min read
Make filled polygons between two curves in Python using Matplotlib
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.To create filled polygons between two curves a PolyCollection filling needs to be created between y1 and y2.Parameters for the above task:
1 min read
How to make Triangle in Python Turtle using onscreenclick?
“Turtle” is a Python feature like a drawing board, which lets us command a turtle to draw all over it! We can use functions like turtle.forward(…) and turtle.right(…) which can move the turtle around. Turtle is also Known as Logo Programming language which commands for movement and drawing produced line or vector graphics, either on screen or with
2 min read
How to make a Twitter Bot in Python?
Twitter is an American microblogging and social networking service on which users post and interact with messages known as "tweets". In this article we will make a Twitter Bot using Python. Python as well as Javascript can be used to develop an automatic Twitter bot that can do many tasks by its own such as: Retweets the tweets with particular #has
3 min read
Make Python API to access Mongo Atlas Database
Prerequisite: Python | Build a REST API using Flask RESTful APIs are a very helpful tool to manage the backend of an application. It can be used to define the architecture as well as manage the dependencies of the application using routes managed by the API. Flask is a popular micro framework for building web applications. In this article, we will
6 min read
Make filled polygons between two horizontal curves in Python using Matplotlib
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. To create filled polygons between two curves a PolyCollection filling needs to be created between y1 and y2. Parameters for the above task
2 min read
Make an Circle Glyphs in Python using Bokeh
Bokeh is a Python interactive data visualization. Unlike Matplotlib and Seaborn, Bokeh renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Plotting the Circle Glyphs Different shapes such as circle, rectangle, poly
4 min read
How to make a Google Translation API using Python?
Google Translate is a free multilingual translation service, based on statistical and neural machine translation, developed by Google. It is widely used to translate complete websites or webpages from one languages to another. We will be creating a python terminal application which will take the source language, target language, a phrase to transla
4 min read
How to make Log Plots in Plotly - Python?
A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. What are the log plots? A log plot is a way of
2 min read
Practice Tags :