Introduction :
Creating animations is an interesting project for new developers. Using circle() function of graphics.h library, you can create an animation effect in your program. In this article, I shall show you how to create simple circle animations using the C or C++ graphics programming language. Here, I create a circle animation program using graphics.h library of Turbo C++ IDE.
About the program :
This program is an animation of circles expanding and contracting at the center of the graphics screen. During the animation, the color of the circles will be changed to create a visual effect. The animation runs continuously until you press a key.
Explanation of the program :
At first, include the libraries such as graphics.h, conio.h and dos.h in the program. You have to declare integer variables such as “mid_x”, “mid_y”, “radius”, “i” and “j” in the main() function. You have to also declare “graphic_driver” and “graphic_mode” variables. Then, initialize the graphics system using initgraph() function.
Now, calculate the mid point of x and y coordinate of the graphics screen using getmaxx() and getmaxy() functions and store in “mid_x” and “mid_y” variables respectively. In the while loop use kbhit() function that checks if a key has been pressed or not. After that, set the drawing color using setcolor() function. Here, I use circle() function to draw circles one by one with different radius.
To create the animation effect, you have to use delay() function. At last, use closegraph() function to close the graphics mode.
How run the program :
You have to install the Turbo C++ IDE on your PC to run the program. Then, open it and create a C or C++ file in Turbo C++ IDE. Now, copy the below source code and paste in your file. Do you know how to copy paste in the Turbo C++ IDE? You have to also know how to use graphics.h in Turbo C++ IDE.
Source code :
The below code is the source code of the circle animation program using graphics.h library of Turbo C++ IDE.
/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
int mid_x, mid_y, radius = 5, i, j = 1;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
mid_x = getmaxx() / 2;
mid_y = getmaxy() / 2;
while (!kbhit())
{
setcolor(j);
for (i = 1; i <= 40; i++)
{
circle(mid_x, mid_y, radius);
delay(100);
radius = radius + 5;
}
setcolor(0);
for (i = 1; i <= 41; i++)
{
circle(mid_x, mid_y, radius);
delay(100);
radius = radius - 5;
}
if (j == 15)
j = 1;
j++;
}
closegraph();
return 0;
}
Output :
If you run the program on your PC, you can see the below image as output.

Conclusion :
Finally, you know how to create a simple circle animation program using the graphics.h library of Turbo C++ IDE by C or C++ graphics programming language. Now, you can create your own animations as you like.
Thank you for visiting my site.