Home » #Technology » Celebrating Independence Day: Coding Creative Indian Flag

Celebrating Independence Day: Coding Creative Indian Flag

As we celebrate India’s Independence Day 2024, it’s a perfect opportunity to delve into a creative project that honors our New Bharat nation’s rich heritage and technological advancements. Today, Let’s take a digital journey and recreate the Indian flag using Python. This exercise not only pays tribute to our national pride but also highlights the power of programming in art and design. So, let’s dive into how you can create a pixel-perfect image of the Indian flag, complete with the Ashoka Chakra, using Python and the Pillow library.

Happy Independence Day 2024!

Before we embark on our coding adventure, let’s take a moment to celebrate. Independence Day is a day of joy, reflection, and pride for all Indian around the world. It marks the anniversary of our nation’s liberation and reminds us of our shared values, aspirations, growth and New Developed Bharat 2047. As we honor this significant day, let’s combine our love for technology and patriotism to create something truly unique.

Flag Design: A Pixel Art Approach

The Indian flag is a symbol of our nation’s diversity, unity, and freedom. It consists of three horizontal stripes—saffron at the top, white in the middle, and green at the bottom—with the Ashoka Chakra (a 24-spoke wheel) centered in the white stripe. For our tech project, we’ll use Python to create a pixel art version of the flag.

Getting Started

To begin, we need to install the Pillow library, which extends Python’s capabilities to handle images. If you haven’t already installed Pillow, you can do so via pip:

pip install pillow

Step-by-Step Coding Guide

Below is a Python script that generates a pixel art image of the Indian flag, including the Ashoka Chakra:

from PIL import Image, ImageDraw
from math import cos, sin, radians

# Define the size of the image
width, height = 300, 180
stripe_height = height // 3
chakra_radius = 20

# Define the center of the white stripe for Chakra placement
chakra_center = (width // 2, stripe_height + stripe_height // 2)

# Create a new image with white background
image = Image.new('RGB', (width, height), 'white')
draw = ImageDraw.Draw(image)

# Draw the three stripes
draw.rectangle([0, 0, width, stripe_height], fill='#FF9933')  # Saffron
draw.rectangle([0, stripe_height, width, stripe_height * 2], fill='white')  # White
draw.rectangle([0, stripe_height * 2, width, height], fill='#138808')  # Green

# Draw the Ashoka Chakra
# Draw the outer circle of the chakra
draw.ellipse([chakra_center[0] - chakra_radius, chakra_center[1] - chakra_radius,
              chakra_center[0] + chakra_radius, chakra_center[1] + chakra_radius],
             outline='#000080', width=3)

# Draw the 24 spokes
for i in range(24):
    angle = i * (360 / 24)
    x_end = chakra_center[0] + chakra_radius * 0.8 * cos(radians(angle))
    y_end = chakra_center[1] - chakra_radius * 0.8 * sin(radians(angle))
    draw.line([chakra_center[0], chakra_center[1], x_end, y_end], fill='#000080', width=1)

# Save the image
image.save('indian_flag_pixel_art.png')
image.show()

Code Explaination:

  1. Setup and Initialization:
    • We create a blank image with a white background using Image.new().
    • Define dimensions for the flag and the Ashoka Chakra.
  2. Drawing the Stripes:
    • The flag is composed of three horizontal stripes—saffron, white, and green. We use draw.rectangle() to draw each stripe with the corresponding colors.
  3. Drawing the Ashoka Chakra:
    • The Chakra is represented by a circle drawn with draw.ellipse().
    • The 24 spokes are created by calculating their positions using trigonometric functions (cos and sin). The spokes are evenly spaced around the Chakra.
  4. Saving and Displaying:
    • The final image is saved as indian_flag_pixel_art.png and displayed using image.show().

This pixel art rendition of the Indian flag is more than just a coding exercise; it’s a testament to how technology can bridge the gap between creativity and heritage. As we celebrate Independence Day, this project reminds us of the incredible ways we can honor our history while embracing the future.

As we honor our freedom, let us commit to building an India where every sunrise brings new growth, every effort scales new heights, and every dream finds its wings.

Happy Independence Day! Jai Hind Jai Bharat 🇮🇳 !

May we continue to advance and celebrate our nation’s spirit and achievements through innovation and creativity.
#AskDushyant

#CodeSnippet #India #Bharat #IndependenceDay2024 #Python

Note: Code tested on Python version 3.10, Feel free to modify the code, experiment with different styles, and make this pixel art flag your own. Whether you're a seasoned programmer or just starting, this project is a fun way to engage with both technology and tradition.

Leave a Reply

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