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



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.