C++ Animation Program Code

  1. Home
  2. Tutorials
  3. CPP
  4. CPP Programs
  5. Graphics Using Dev C++
  6. Program

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:

c++ animation program code using graphics.h

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.

Comments
Please select compiler type from right most tool bar drop down option as TDM GCC 32-bit debug.
~asada
15/Apr/23 08:21 am
not working [error]sstream:no such directory or file.
Bibas Thapa
24/Dec/22 10:38 am
Login to TRACK of Comments.