ADVERTISEMENT
ADVERTISEMENT

Home » C programs » graphics.h header file functions

rectangle() and bar() functions of graphics.h in C

In this article, we are going to learn about the rectangle() and bar() functions of graphics.h header file in C programming language and use them with the help of examples.
Submitted by Manu Jemini, on March 18, 2018

Creating a rectangle and bar in with graphics.h is fairly easy. What it takes is to initialize a graph with two parameters and a path to the "bgi" folder in your system.

After that, we will call the function called rectangle() with four numbers as the four coordinates of the rectangle. With these parameters, we will have a rectangle on our screen.

To make a bar on the screen, all we need to do is call the bar() function with four numbers as the co-ordinate of the bar. These four co-ordinates decide the size of the bar.

To use these function in your program, we would need to include graphics.h file in your program. You should also use getch() function to make the screen freeze.

graphics.h - rectangle() and bar() functions Example in C



#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>

void main() {
	//initilizing graphic driver and 
	//graphic mode variable
	int graphicdriver=DETECT,graphicmode;

	//calling initgraph function with 
	//certain parameters
	initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");

	//Printing message for user
	outtextxy(10, 10 + 10, "Program to draw rectangle and bar in C graphics");

	//calling rectangle function with certain parameters
	rectangle(50, 100, 100, 50);

	// calling bar function
	bar(200, 50, 150, 100);

	getch();
}

Output

graphics.h - rectangle() and bar() functions example in C

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.