Python Tutorials

How to Make Indian Flag Using Python

Hello, Welcome back to another Python Tutorial. Here, we will be making “The Great Indian Flag” using Python Turtle Graphics. 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. 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 forwarding 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 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.

Python Implementation 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()

Try to Make Indian Flag Using Python with above code.

Check Our Other Python Tutorials Here

KSR

Hi there! I am the Founder of Cyber World Technologies. My skills include Android, Firebase, Python, PHP, and a lot more. If you have a project that you'd like me to work on, please let me know: contact@cyberworldtechnologies.co.in

Related Articles

Leave a Reply

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

Back to top button