C Program to Draw a Circle Using C Graphics

Here is a C program to draw a circle on screen using graphics.h header file. In this program, we will draw a circle on screen having centre at mid of the screen and radius of 80 pixels. We will use outtextxy and circle functions of graphics.h header file. Below is the detailed descriptions of graphics functions used in this program.

Function Description
initgraph initgraph is a fundamental function in Turbo C graphics that initializes the graphics system. It sets up the graphics mode, graphics driver, and the location of the BGI (Borland Graphics Interface) driver file. This function is a prerequisite for any graphics operation and must be called before drawing on the screen.
getmaxx The getmaxx function retrieves the maximum X-coordinate available in the current graphics mode. It provides the width of the graphics screen in terms of pixel coordinates.
getmaxy getmaxy is similar to getmaxx but retrieves the maximum Y-coordinate available in the current graphics mode. It provides the height of the graphics screen in terms of pixel coordinates.
outtextxy The outtextxy function is used to display text on the graphics screen at a specified position. It allows you to incorporate textual information into your graphics applications.
circle The circle function draws a circle on the screen with the specified center and radius. It is a fundamental function for creating circular shapes and patterns in Turbo C graphics.
closegraph closegraph terminates the graphics mode and deallocates any system resources that were acquired during the initialization of the graphics system. It should be called before exiting a graphics program.

C program to draw circle using c graphics

In this program we first initialize graphics mode, by passing graphics driver(DETECT), default graphics mode and specifies the directory path where initgraph looks for graphics drivers (*.BGI). It is the first step you need to do during graphics programming. Setting graphics driver as DETECT, means instructing the compiler to auto detect graphics driver. Here we are using getmaxx and getmaxy function to find the center coordinate of the screen.

#include<stdio.h>
#include<graphics.h>

int main(){
   int gd = DETECT,gm;
   int x ,y ,radius=80;
   initgraph(&gd, &gm, "C:\\TC\\BGI");
   /* Initialize center of circle with center of screen */
   x = getmaxx()/2;
   y = getmaxy()/2;

   outtextxy(x-100, 50, "CIRCLE Using Graphics in C");
   /* Draw circle on screen */
   circle(x, y, radius);

   closegraph();
   return 0;
}
Program Output C graphics program to draw a circle

Conclusion

In conclusion, this tutorial has guided you through the creation of a dynamic circle using Turbo C graphics, offering a hands-on exploration of fundamental graphics programming concepts. You've learned how to set up the Turbo C environment, draw shapes, add colors, and even dynamically take user input to create visually appealing graphics.

Graphics programming is a captivating field that allows developers to blend logic with creativity, producing visually stunning applications. Turbo C, though considered a classic, provides an educational and nostalgic environment for grasping essential graphics principles. This tutorial serves as a stepping stone into the expansive world of visual programming, offering a foundation that can be extended to more complex graphics projects.

As you embark on further adventures in graphics programming, consider delving into advanced topics like animation, interaction, and incorporating multimedia elements. The principles learned in Turbo C graphics are transferable, and the skills acquired here form a solid base for exploring modern graphics libraries and frameworks.

Remember, the joy of graphics programming lies in experimentation and creativity. Use this newfound knowledge to bring your ideas to life on the digital canvas. Whether you're crafting games, simulations, or interactive applications, Turbo C graphics provides a nostalgic yet robust platform for your explorations. Embrace the possibilities, and let your imagination flourish in the realm of visual programming. Happy coding!


Related Topics
C graphics program to draw an eclipse
C graphics program to draw concentric circles
C program to draw sine wave graph on screen
C program to draw pie chart using graphics
C graphics program to draw digital clock
C program for bouncing ball animation
C graphics program for moving car animation
List of all C Graphics Programs