How to create banner by c with source code

banner

Introduction :

Using C or C++ programming language, you can create any type of graphic design on the graphics window. Creating a visually appealing banner using the C or C++ graphics programming language is an exciting and creative project for new programmers. With the help of graphics.h library of Turbo C++ IDE, you can design a basic visually appealing text banner with various fonts, colors and animations in graphics mode.

In this article, I shall explore you how to create an animated digital banner program using graphics.h library of Turbo C++ IDE by C or C++ graphics programming language. Here, I build a graphical animated banner which shows my name and address dynamically on the graphics screen. This is a graphics program of creating banner which build by C or C++ graphics programming language.

You can also see draw colorful arc program, drawing design program or other graphics project by C or C++ programming language in my site.

What is banner :

A banner is a graphic or textual display that is generally used for advertising brand, event, product or service. Banners can be found in both physical (print) and digital formats. Physical or print banner is a printed sheet or piece of fabric or paper that displays information, advertisements or messages of events, trade shows, parties etc. Digital banner is a graphic element that used to promote products, services or events on a website or apps.

Both digital and physical or print banners are commonly used for communication and marketing a specific message and capture the attention of the audience. The primary function of a banner is to capture attention and show information or messages to the public. There are different type of banners you can see such as web banners, print banners, street banners, social media banners, email banners and more.

About The Program :

The program is about to create a basic animated text banner that display and moves horizontally in graphics mode. When you run the program on your pc, you can see a scrolling text banner with the name “Puskar Jasu” and address “Gangadharpur” moving from right to left on the graphics screen repeatedly. The animation will continue until you press a key. After pressing any key, the program will be stopped. You can change the name and address of the banner with your name and address.

Explanation of the program :

At the beginning, you have to include several header files such as graphics.h, conio.h and dos.h in the program. For graphical function, you can use graphics.h library. For use kbhit() function, you have to include conio.h library. To use sleep() and delay() function, you can include dos.h library. In the main function, declare integer variables “xmax”, “ymax”, “y”, “i”, “graphic_driver” and “graphic_mode” for screen dimensions, loop counter and graphics mode settings.

Now, initialize the graphics mode by calling initgraph() function with “graphic_driver” and “graphic_mode” arguments. The third argument (“//turboc3/bgi”) specifies the location of the BGI file of my pc. You have to change the location of the BGI file of Turbo C++ IDE of your pc. Then, you have to set the background and drawing color using setbkcolor() and setcolor() functions respectively.

Next, retrieve the maximum x and y coordinates of the graphics window using getmaxx() and getmaxy() functions and store them in “xmax” and “ymax” variables respectively. Calculate the half of the screen height and store in “y” variable to display the text vertically in the middle of the screen. Here, I have used a “for” loop inside the “while” loop.

In the while loop, I use kbhit() function to check any key pressed or not. If you press any key, the animation will be stopped. Inside the “for” loop, set the font style, direction and size of the displayed text using settextstyle() function. Using outtextxy() function, display each letter of the name and address at different positions to create the moving animation effect on the graphics screen.

Using sleep() and delay() functions, slow down the scrolling and control the speed of the animation of the program. Call the cleardevice() function to clear the screen for the next frame. At last, you have to close the graphics mode using closegraph() function.

How run the program :

This program build by C or C++ graphics programming language. If you want to run this program on your computer, you have to install the Turbo C++ IDE in your computer. If you have not installed Turbo C++ IDE, first install the Turbo C++ IDE on your pc. After that Just copy my following source code and paste it in your C or C++ file or create a C or C++ file and write the code manually. Then run the program after build and see the output on your pc.

In this program, I use graphics.h library. To use graphics.h, you have to show the path of graphics.h like my code. initgraph(&gdriver, &gmode, “//turboc3/bgi”); Your path may be different from mine. You have to show the bgi folder of your pc.If you do not know how to copy paste in the Turbo C++ IDE, click here. You can also see my other post to know how to use graphics.h in Turbo C++ IDE.

Source code :

The following code is the source code of my banner program which builds by C or C++ graphics programming language. You can copy the following code and use it in your project.

/* Develop by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
    int xmax, ymax, y, i;
    int graphic_driver = DETECT, graphic_mode;
    initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
    setbkcolor(4);
    setcolor(14);
    xmax = getmaxx();
    ymax = getmaxy();
    y = ymax / 2;
    while (!kbhit())
    {
	for (i = 0; i <= xmax + 1060; i++)
	{
	    settextstyle(1, 0, 8);
	    outtextxy(xmax - i, y, "P");
	    outtextxy(xmax + 50 - i, y, "U");
	    outtextxy(xmax + 100 - i, y, "S");
	    outtextxy(xmax + 150 - i, y, "K");
	    outtextxy(xmax + 200 - i, y, "A");
	    outtextxy(xmax + 250 - i, y, "R");
	    outtextxy(xmax + 300 - i, y, "");
	    outtextxy(xmax + 350 - i, y, "J");
	    outtextxy(xmax + 380 - i, y, "A");
	    outtextxy(xmax + 430 - i, y, "S");
	    outtextxy(xmax + 480 - i, y, "U");
	    outtextxy(xmax + 530 + 50 - i, y, "G");
	    outtextxy(xmax + 580 + 50 - i, y, "A");
	    outtextxy(xmax + 630 + 50 - i, y, "N");
	    outtextxy(xmax + 680 + 50 - i, y, "G");
	    outtextxy(xmax + 730 + 50 - i, y, "A");
	    outtextxy(xmax + 780 + 50 - i, y, "D");
	    outtextxy(xmax + 830 + 50 - i, y, "H");
	    outtextxy(xmax + 880 + 50 - i, y, "A");
	    outtextxy(xmax + 910 + 70 - i, y, "R");
	    outtextxy(xmax + 960 + 70 - i, y, "P");
	    outtextxy(xmax + 1010 + 70 - i, y, "U");
	    outtextxy(xmax + 1010 + 120 - i, y, "R");
	    if (i == 550 || i == 1200)
		sleep(2);
	    delay(3);
	    cleardevice();
	}
    }
    closegraph();
    return 0;
}

Output :

You can also see the output of my program in my YouTube channel.

Conclusion :

By the end of this article, you have a basic understanding of how you can draw a text banner using C or C++ graphics programming language in graphics mode. Now, you can create more complex programs with your idea brings to life on the digital canvas. If you see my code and use it in your program, I shall be glad to you. Thank you for visiting my site.

Scroll to Top