circle() and ellipse() functions of graphics.h in C

In this article, we are going to learn about the circle() and ellipse() functions of graphics.h header file in C programming language and then create a circle and ellipse using these functions.
Submitted by Manu Jemini, on March 18, 2018

Making a circle and an ellipse in C can be done easily. How to do is, 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 coordinates of the center and radius. So this function will create a circle with a center with the given radius.

To make an ellipse on the screen, all we need to do is call the ellipse() function with six numbers as the coordinates of the ellipse. These six co-ordinates decide the location of the ellipse, angles, and radius from X-axis and Y-axis.

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 - circle() and ellipse() 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 circle and ellipse in C graphics");

	//calling circle function
	circle(100, 100, 50);

	//calling ellipse function
	ellipse(300,110,0,360,100,50);

	getch();
}

Output

graphics.h - circle() and ellipse() functions example in C




Comments and Discussions!

Load comments ↻






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