C Program to Draw Concentric Circles of Different Colors Using C Graphics

Here is a C graphics program to draw concentric circle on screen using graphics.h header file. In this program, we will draw four circle on screen having centre at mid of the screen and radius 30, 50, 70 and 90 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 It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode.
getmaxx It returns the maximum X coordinate in current graphics mode and driver.
getmaxy It returns the maximum Y coordinate in current graphics mode and driver.
outtextxy It displays a string at a particular point (x,y) on screen.
circle It draws a circle with radius r and centre at (x, y).
setcolor It changes the current drawing colour. Default colour is white. Each color is assigned a number, like BLACK is 0 and RED is 4. Here we are using colour constants defined inside graphics.h header file.
closegraph It unloads the graphics drivers and sets the screen back to text mode.

C program to draw concentric circles using 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 centre coordinate of the screen and setcolor function to change he colour of drawing.


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

   outtextxy(240, 50, "Concentric Circles");
   /* Draw circles on screen */
   circle(x, y, 30);
   circle(x, y, 50);
   circle(x, y, 70);
   circle(x, y, 90);

   return 0;
Output C graphics program to draw an eclipse


In conclusion, this tutorial has guided you through the process of creating a dynamic and visually engaging program in C to draw concentric circles of different colors using Turbo C graphics. By exploring fundamental graphics functions, you've gained insights into setting up the Turbo C environment, drawing circles, incorporating vibrant colors, and even making the program interactive by dynamically taking user input.

Graphics programming is an exciting domain where logic converges with creativity, and Turbo C, with its nostalgic appeal, serves as an ideal environment for honing these skills. The knowledge acquired from this tutorial forms a robust foundation for further exploration into the vast and captivating world of visual programming.

As you progress in your graphics programming journey, consider expanding your concentric circle project by experimenting with different shapes, patterns, or exploring more advanced techniques such as animations or interactive interfaces. Turbo C graphics, while considered a classic, provides an enduring platform for understanding graphics principles that seamlessly translate into contemporary programming environments.

The skills cultivated through this tutorial extend beyond drawing concentric circles; they empower you to tackle diverse graphics-related challenges. Whether you're inspired to create visually stunning applications, develop games, or craft interactive simulations, Turbo C graphics provides a nostalgic yet powerful canvas for your creative pursuits.

Remember, the essence of graphics programming lies in the fusion of precision and artistic expression. Embrace the creative possibilities, push the boundaries of visual representation, and continue your journey into the dynamic and visually enchanting world of graphics programming. Happy coding!

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