C++ Animation Program Code
Source Code:
// including graphics header file
#include<graphics.h>
// defining max height and width
#define MAX_WIDTH 800
#define MAX_HEIGHT 500
// C++ main function
int main( ){
// initialization of graphics window
initwindow( MAX_WIDTH , MAX_HEIGHT , "MY First Program");
// for displaying limited objects
int total = 1;
// inifinite loop
while(!kbhit()) {
// randomizing various objects parameters
int radius = 10 + (rand() % 100);
int left = 1 + (rand() % MAX_WIDTH);
int top = 1 + (rand() % MAX_HEIGHT);
int color = 1 + (rand() % 16);
int fs = 1 + (rand() % 10);
// using random parameters
setfillstyle(fs, color);
setcolor(color);
circle(left, top, radius);
floodfill(left,top,color);
// delay function is used for pause
delay(200);
// clear device after 30 objects displayed
if(total > 30) {
cleardevice();
total = 1; // starting count from 1
}
total++; // counting graphic objects
}
getch();
// closing graphics console
closegraph();
return 0;
}
Output:
Working:
In this program example C++ graphics.h header file is used to draw circle objects of different radius at random x,y coordinates. This animation source code is compiled and tested using Dev-C++ IDE.