ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Home » C programs » graphics.h header file functions

Create circles inside various circles using graphics.h in C

In this article, we are going to learn about the setcolor () and circle() functions of graphics.h header file in C programming language and use them to create circles inside various circles.
Submitted by Manu Jemini, on March 20, 2018

To create a circle in C with the help of graphics.h file requires us to, first initialize a graph with two parameters and a path to the bgi folder in your system.

After that we will call the function called circle() with three numbers as the co-ordinates of the center and radius. So this function will create a circle with a center with the given radius.

We will set the color of the circle by passing the parameters of the color, to make them look colorful.

The Trick is to create multiple circles with the same center and with different color and radius. This approach is very useful as it will be appeared as we are making circle inside a circle with beautiful colors,

The Center of the circle is defined by the first and the second parameter passed to this function.

graphics.h - Program to Create circles inside various circles in C



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

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

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

	//Printing message for user
	outtextxy(10, 10 + 10, "Program to draw a circle inside various circles in C graphics");

	//creating circle inside circle
	setcolor(RED);
	circle(200,200,100);

	setcolor(BLUE);
	circle(200,200,80);

	setcolor(YELLOW);
	circle(200,200,60);

	setcolor(BROWN);
	circle(200,200,40);

	getch();
	return 0;
}

Output

graphics.h - design circles within circles program in C

ADVERTISEMENT




Comments and Discussions

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.