Celebrate Diwali In Coding Ninjas Style

Diwali With Coding Ninjas Style
Diwali With Coding Ninjas Style

Introduction

Most of us love Diwali, especially the beautiful light work and the celebrations that follow this sacred day. Regardless of where one comes from in India, most have positive memories of this time of the year. It is a festival of lights and people from all backgrounds find that there is much this day has to offer in terms of fun, entertainment, and colours.

However, with the growing pollution levels and an increase in the average temperature of Earth in general, it is highly advised that we engage in burning fireworks as infrequently as possible. Animals such as dogs, cows, squirrels, and even birds get hurt due to the amount of fire and heat involved when celebrating with firecrackers. The noise from these crackers too disturbs and hurts them.

This Diwali instead of firecrackers, crack patterns, and problems with Coding Ninjas.

Also, here is the link for the Diwali giveaway!


Diwali with Turbo C

Let us make a program that will launch a rocket and wish you Happy Diwali. This program will work with Turbo C compilers, however, online compilers will not work as multiple assets cannot be initiated and key elements such as graphics.h cannot be loaded.

#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<math.h>
#include<dos.h>

int main()
{
int gd, gm;
int x, y;
int i, j, kk;

detectgraph(&gd, &gm);
initgraph(&gd, &gm,"c:\\tc\\bgi");

setcolor(WHITE);
line(0, 400, 640, 400);
rectangle(300, 330, 340, 400);
rectangle(310, 320, 330, 330);
setcolor(4);
line(319, 280, 319, 398);
line(320, 280, 320, 398);
rectangle(320, 280, 330, 300);
outtextxy(340, 280, "PRESS ENTER TO LAUNCH THE ROCKET");
getch();

for (j=400; j<640; j++)
{
cleardevice();
setcolor(WHITE);
line(0, j, 640, j);
rectangle(300, j-70, 340, j);
rectangle(310, j-80, 330, j-70);

setcolor(RED);
line(319, 280, 319, 400);
line(320, 280, 320, 400);
rectangle(320, 280, 330, 300);
setcolor(YELLOW);
circle(325,300,2);

delay(5);
}

for (i=400; i>340; i--)
{
cleardevice();
setcolor(RED);
line(319, i, 319, i-120);
line(320, i, 320, i-120);
rectangle(320, i-120, 330, i-100);

setcolor(YELLOW);
circle(325, i-100, 2);
delay(25);
}

cleardevice();
kk = 0;
for (j=100; j<350; j++)
{
if (j%20==0)
{
setcolor(kk);
kk=kk+3;
delay(50);
}
ellipse(320, 30, 0, 360, j+100, j+0);
}

for (j=100; j<350; j++)
{
if (j%20==0)
{
setcolor(BLACK);
delay(2);
}
ellipse(320, 30, 0, 360, j+100, j+0);
}

cleardevice();
i = 0;
while (!kbhit())
{
setcolor(i++);
settextstyle(GOTHIC_FONT,HORIZ_DIR,5);
outtextxy(70, 150, "Coding Ninjas Wishes You A Happy Diwali!!");
delay(90);
}

getch();
return 0;
}

Diwali with C++

Here is a program for C++ that will initiate the launch of firecrackers with the launch() function and also display any Diwali text {(settextstyle)} you wish. This function fundamentally calls upon the mess() function that will display the Diwali greeting and the fire() function that will call another function, the cracker() function. Notably, the cracker() function allows multiple firecrackers to become activated. If you wish, then you can even use sine or cosine functions for creating three-dimensional fireworks and various other effects.

#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <time.h>
 
void crackers()
{
    setfillstyle(SOLID_FILL, RED);
    line(80, 680, 130, 680);
    line(80, 680, 105, 630);
    line(105, 630, 130, 680);
    floodfill(105, 650, 15);
 
    setfillstyle(SOLID_FILL, BLUE);
    line(300, 680, 350, 680);
    line(300, 680, 325, 630);
    line(325, 630, 350, 680);
    floodfill(325, 650, 15);
 
    setfillstyle(SOLID_FILL, BROWN);
    line(500, 680, 550, 680);
    line(500, 680, 525, 630);
    line(525, 630, 550, 680);
    floodfill(525, 650, 15);
 
    setfillstyle(SOLID_FILL, GREEN);
    line(700, 680, 750, 680);
    line(700, 680, 725, 630);
    line(725, 630, 750, 680);
    floodfill(725, 650, 15);
 
    setfillstyle(SOLID_FILL, CYAN);
    line(920, 680, 970, 680);
    line(920, 680, 945, 630);
    line(945, 630, 970, 680);
    floodfill(945, 650, 15);
}
 
void fire()
{
    int v = 625, u = 630, g = 630, h = 625,
        a = 325, n = 325, e = 325, x = 320, j = 330;
    int b = 525, m = 525, f = 525, y = 520,
        k = 530, c = 725, i = 725, o = 725,
        z = 720, l = 730;
    int t = 630, s = 625;
 
   crackers();
 
    while (h != 435) {
        crackers();
 
        line(n, g, n, h);
        line(m, u, m, v);
        line(o, u, o, v);
        line(a, u, x, v);
        line(b, u, y, v);
        line(c, u, z, v);
        line(e, t, j, s);
        line(f, t, k, s);
        line(i, t, l, s);
 
              a = a - 10;
        x = x - 10;
        u = u - 10;
        v = v - 10;
        g = g - 10;
        h = h - 10;
        b = b - 10;
        y = y - 10;
        c = c - 10;
        z = z - 10;
        t = t - 10;
        s = s - 10;
        e = e + 10;
        f = f + 10;
        i = i + 10;
        j = j + 10;
        k = k + 10;
        l = l + 10;
 
              delay(30);
    }
}
 

void mess()
{
    settextstyle(8, 0, 5);
 
    outtextxy(200, 350, "HAPPY DIWALI");
}
 
void launch()
{
    int q1 = 630, q2 = 590;
 
  
    while (q2 != 330) {
        cleardevice();
 
        fire();
        mess();
 
        line(105, q1, 105, q2);
        line(945, q1, 945, q2);
 
        q1 = q1 - 20;
        q2 = q2 - 20;
 
        fire();
        mess();
 
        delay(30);
    }
}
 
void main()
{
    int gd = DETECT, gm;
 
    initgraph(&gd, &gm, "C:\\"
                        "turboc3\\bgi");
 
    launch();
 
    setfillstyle(SOLID_FILL, WHITE);
    circle(105, 370, 20);
    floodfill(104, 371, 15);
    floodfill(106, 371, 15);
 
    setfillstyle(SOLID_FILL, WHITE);
    circle(945, 370, 20);
    floodfill(944, 371, 15);
    floodfill(946, 371, 15);
 
    getch();
 
    closegraph();
 
    return 0;
}

Diwali with HTML, CSS & JS

Building programs to wish Happy Diwali is fun. But, how about trying a truly interactive and immersive digital Diwali experience? With the combination of HTML, CSS and JavaScript, you can build an interactive web application (or page) that will facilitate beautiful colourful fireworks getting activated whenever and wherever you click on the screen.

And obviously, a Diwali greeting will be there! With these following scripts, you can go beyond a simple program like an experience without using additional assets, libraries or files and build a beautiful digital Diwali celebratory experience with ease.

HTML

<html><head>

<title>Have an amazing Diwali</title>
   
</script>
</head>
<body>
    <div class="container-fluid">
        <h1 class="red-text text-center">Have an awesome Diwali, Ninjas!</h1>
      <center><span>click on screen</span>  </center>
    </div> 

<footer class="footer footer-inverse" style=" margin-bottom: 0;">
      <div class="container">
        <!-- Start of SimpleHitCounter Code -->
        
        <!-- End of SimpleHitCounter Code -->        
      </div>
</footer>
</body></html>

CSS

.red-text {
    font-family:Pacifico;
    color: red;
    font-size: 46px;
  }
html,body{height:100%;margin:0;padding:0;background-image: url("http://santhosh.comxa.com/dsm/moonlight.jpg");}
ul,li{text-indent:0;text-decoration:none;margin:0;padding:0}
img{border:0}
body{background-color:#000;color:#999;font:100%/18px helvetica, arial, sans-serif}
canvas{cursor:crosshair;display:block;left:0;position:absolute;top:0;z-index:20}
#header img{width:100%; height:20%;}
#bg img{width:100%; height:80%;}
#header,#bg{position:fixed;left:0;right:0;z-index:10}
#header{top:0}
#bg{position:fixed;z-index:1;bottom:0}
audio{position:fixed;display:none;bottom:0;left:0;right:0;width:100%;z-index:5}

Now, in order to make the “Happy Diwali Ninjas” message interactive, we must also add JS and provide the function we want. In order to use JS, search for the kind of UI/UX you wish for (clicking, button-activated, etc.) and copy-paste that into a file. The JS along with the HTML and CSS files will together build the entire interface.

Key Takeaway

So, what are you waiting for? I

mpress your family, teachers, or even friends with the digital Diwali greetings and fireworks.

If you wish to avail a huge discount for Coding Ninjas courses, then use this link to get the Diwali giveaway benefits. Happy Diwali!

Exit mobile version