C++ | My Simple Animation

C++ | Simple Animation


Hello peeps! Lord Hypersonic greets you. So you must be wondering what program is this? It is a simple program which will create a simple animation using the functions of graphics.h (click here to download graphics.h).
To use graphics.h in your code::blocks follow the steps given below:-

  1. After downloading, extract the downloaded files (there will be three files).
  2. Copy graphics.h and winbgim.h in include folder (looks like this: ../CodeBlocks/MinGW/include ).
  3. Now copy libbgi.a to the lib folder ( ../CodeBlocks/MinGW/lib).
  4. Now open code::blocks.
  5. Go to settings >> Compiler >> Linker Settings.
  6. Click on Add button under the Link Libraries part and click Browse
  7. Select the libbgi.a file copied to the lib folder.
  8. In right part (i.e., Other linker options: ), paste the commands: -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  9. Click Ok.

Now you can compile the given code ðŸ˜„. 



Source Code:-

/**************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
********************************************** Animation in c++ ************************************************************************
********************************************** ************************************************************************
********************************************** Animation by: Jatin bal ************************************************************************
********************************************** ************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
***************************************************************************************************************************************************************
**************************************************************************************************************************************************************/

#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

int main()
{
int g=DETECT,d;
initgraph(&g,&d,"\tc\bgi");
outtextxy(getmaxx()/2,getmaxy()/2,"Press Any Key To START!");
getch();
cleardevice();
for(int i=1; i<=150; i++)
{
cleardevice();
line(50,100,50+i,100); //x: 200
delay(10);
}
for(int i=1; i<=30; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,100+i); //y: 130
delay(10);
}
for(int i=1; i<=50; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,200-i,130); // x: 150
delay(10);
}
for(int i=1; i<=100; ++
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,130+i); //y: 230
delay(10);
}
for(int i=1; i<=50; ++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,150-i,230); //x: 100
delay(10);
}
for(int i=1; i<=50; ++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,100-i,230-i); // x:50 y:180
delay(10);
}
for(int i=1; i<=50; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,50+i,180); //x: 100
delay(10);
}
for(int i=1; i<=20; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(200,130,150,130);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,100+i,180+i); // x:120 y:200
delay(10);
}
for (int i=1; i<=70; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,200-i); //x:120 y:130
delay(10);
}
for(int i=1; i<=70; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,120-i,130); //x: 50
delay(10);
}
for (int i=1; i<=30; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,130-i); //y:100
delay(10);
}
for (int =1; i<=100; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,250+i,230); // x: 350
delay(10);
}
for(int i=1; i<=180; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,270+i,32);
delay(10);
}
for (int i=1; i<=180; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,270+i,32);
delay(10);
}
for(int i=1; i<=100; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,350-i,103); //x: 250
delay(10);
}
for(int i=1; i<=20; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,103+i); //y: 123
delay(10);
}
for(int i=1; i<=30; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,250+i,123); //x: 280
delay(10);
}
for(int i=1; i<=87; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,280,123);
line(280,123,280,123+i); //y: 210
delay(10);
}
for(int i=1; i<=30; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,280,123);
line(280,123,280,210);
line(280,210,280-i,210); // x: 250
delay(10);
}
for(int i=1; i<=20; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,280,123);
line(280,123,280,210);
line(280,210,250,210);
line(250,210,250,210+i); // x: 230
delay(10);
}
for(int i=1; i<=30; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,280,123);
line(280,123,280,210);
line(280,210,250,210);
line(250,210,250,230);
line(310,120,310,120+i); // y: 150
line(310,178,310,178+i); // y: 208
delay(10);
}
for(int i=1; i<=40; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,280,123);
line(280,123,280,210);
line(280,210,250,210);
line(250,210,250,230);
line(310,123,310,152);
line(310,180,310,210);
line(310,150,310+i,150); // x: 350
line(310,208,310+i,208); // x: 350
delay(10);
}
for (int i=1; i<=180; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,280,123);
line(280,123,280,210);
line(280,210,250,210);
line(250,210,250,230);
line(310,123,310,152);
line(310,180,310,210);
line(310,150,350,150);
line(310,208,350,208);
arc(350,136,270,270+i,16);
arc(350,194,270,270+i,16);
delay(10);
}
for(int i=1; i<=40; i++)
{
cleardevice();
line(50,100,200,100);
line(200,100,200,130);
line(200,130,150,130);
line(150,130,150,230);
line(150,230,100,230);
line(100,230,50,180);
line(50,180,100,180);
line(100,180,120,200);
line(120,200,120,130);
line(120,130,50,130);
line(50,130,50,100);
line(250,230,350,230);
arc(350,198,270,90,32);
arc(350,135,270,90,32);
line(350,103,250,103);
line(250,103,250,123);
line(250,123,280,123);
line(280,123,280,210);
line(280,210,250,210);
line(250,210,250,230);
line(310,123,310,152);
line(310,180,310,210);
line(310,152,350,152);
line(310,210,350,210);
arc(350,136,270,90,16);
arc(350,194,270,90,16);
line(350,120,350-i,120);
line(350,178,350-i,178);
delay(10);
}
line(0,400,getmaxx(),400);
outtextxy(getmaxx()/2,401,"ANIMATION BY \"JATIN BAL\"");
getch();
closegraph();

}
THIS IS WHAT I MADE USING graphics.h, share your code in comments.

ENJOY 😄




No comments

Powered by Blogger.