Introduction :
In graphics programming, you have to draw various coloring shapes such as circles. Using C or C++ programming language, you can draw and color circles one by one that create an animation effect. In this article, I shall show you how to draw coloring circle one by one in C or C++ graphics programming language. Here, I use the graphics.h library of Turbo C++ IDE for drawing colored circle animation program.
About the program :
This is a simple program for drawing and coloring circles one by one in C or C++ language. After running the program, you can see a series of circles drawn and colored one by one on the graphics screen. The program continues until you press any key.
Explanation of the program :
At first, include graphics.h, conio.h and dos.h in the program. Then, declare integer variables such as “i”, “x”, “a”, “b”, “graphic_driver” and “graphic_mode” in the main() function. After that, initialize the graphics system using initgraph() function. Using getmaxx() function, gets the maximum x coordinate value of the graphics screen.
In the while loop, you can use kbhit() function to check any key is pressed or not. The setcolor() function is used to set the current drawing color. To draw circle on the screen, use circle() function. Using setfillstyle() and floodfill() functions, set the fill style and color of the circles. The delay() function is used to add a delay between drawing each circle. Finally, close the graphics mode using closegraph() function.
How run the program :
If you run the program on your PC, you have to install the Turbo C++ IDE. Then, open it and create a C or C++ file with .c or .cpp extension. After that, Just copy my following source code and paste it in your C or C++ 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 of the program :
The following code is the source code of drawing colored circles one by one program in C programming language.
/* Develop by Puskar Jasu*/
#include <graphics.h>
#include <conio.h>
#include <dos.h>
int main(void)
{
int i = 0, x, a = 10, b = 0;
int graphic_driver = DETECT, graphic_mode;
initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
x = getmaxx() / 2;
setcolor(4);
while (!kbhit())
{
setcolor(i);
setfillstyle(SOLID_FILL, i);
circle(b + 25, a, 10);
floodfill(b + 25, a, i);
delay(100);
if ((b + 25) >= x + x)
{
a += 20;
b = 0;
i = 0;
}
i++;
b += 25;
}
closegraph();
return 0;
}
Output of the program :
After running the program on your PC, you can see the output of the program. You can see the output in my YouTube channel.
Conclusion :
At last, you have learned how to create coloring circle one by one in C or C++ graphics programming language. You can use my code in your project. Thank you for visiting my site.