Indian Flag Using Python Turtle

indian flag using python turtle

Introduction:

In this project, we will show how to use Turtle graphics using Python to make our Indian flag. Turtle is a pre-installed library in Python used to design a virtual canvas. In simple language, it’s a tool that helps you to draw on a board in your program with the help of a few commands. These commands are basically related to directions or the start and stop of drawing. So gear up with your IDE and try this out!

Explanation:

As turtle is a library in Python, we will first start by importing it into our program using the import keyword. Next, we import * from the turtle, this means that all the functions defined in the turtle library will be imported and are free to use in this code.

The second step is to create a screen or your drawing board for the graphics. This can be done by using a turtle.Screen(). This assigns a screen to the variable screen. Now to draw, you will need a medium. On paper, it’s your pencil, and with the virtual board or screen it’s the turtle. Hence, we assign turtle to the variable t using turtle.Turtle() and set its speed to 0. Speed settings can be set between 1 (slowest) to 10 (fastest). At speed 0, all animations are stopped and the turtle can go as fast as possible.

Now, the only thing left to do is to draw.

Start by lifting the pen up which means that it won’t draw whatever direction it goes. Now set the location of the pen(turtle) to the coordinates (-400,250) using method goto(). The coordinates may differ from person to person. Now, initially, the screen is white, so you won’t need to create the white rectangle for the flag but green and orange and also the Ashoka Chakra.

Firstly, we set the color to orange and next use begin_fill() so that it fills the shape with orange color as the border is created. Next, we set the directions for the turtle to move using methods like right(), left(), and forward(). The trick we used here is after we created the orange rectangle, we extended the vertical left line to reach the co-ordinated where the green rectangle begins. The same steps are to be followed for the green rectangle.

Remember to penup() as we move to the center of the white rectangle for the Ashoka Chakra.

The logic here is to make a big circle with the color navy blue. Then draw another circle concentric to this circle with a smaller radius. Concentric circles are circles with the same center with different radii. This will give a circular border effect. Similarly, we draw a small navy blue circle over the white circle in the center. Repeat the steps! =>

t.penup() => t.goto() => t.pendown() => t.color() => t.begin_fill() => t.circle() => t.end_fill()

Following the above step next we draw 24 circles on the border and connect to the center by drawing spokes and this is done by using the for loop. And bravo! You have learned to use a turtle and make your flag in it.

Source Code:

				
					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

Find More Projects

library management system using python with source code using Python GUI Tkinter (Graphical User Interface) How to Run the code: Introduction:  Imagine …

Space Shooter Game Using Python with source code Overview: A space shooter game typically involves controlling a spaceship to navigate through space …

Hotel Management System Using Python with source code Introduction: Welcome to our blog post introducing a helpful tool for hotels: the Tkinter-based …

Student Management System Using Python Introduction: The Student Management System is a comprehensive software solution designed to streamline the process of managing …

Billing Management System using Python introduction: The Billing software using python is a simple yet effective Python application designed to facilitate the …

Medical Management System using Python with Complete Source code [By using Flask Framework] Introduction Hospital Management System The Hospital Management System is …

More Python Projects
Get Huge Discounts

All Coding Handwritten Notes

Browse Handwritten Notes