At least four C++ programs based on Graphics functions

/////////////////////////////////////////////////////////////////////////////////////////////
//Hello India Program 
//////////////////////////////////////////////////////////////////////////////////////////// 
#include<stdio.h>
void main()
{
clrscr();
printf(" HELLO INDIA ");
getch();
}

///////////////////////////////////////////////////////////////////////////////////////////
//Drawing a line on screen
//////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
line(0,0,250,250);
getch(); 
}
output of the program will be like this
  
//////////////////////////////////////////////////////////////////////////////////////////// 
//Drawing a circle
/////////////////////////////////////////////////////////////////////////////////////////// 
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
circle(250,250,50);
getch(); 
}
 output of the program will be like this
  
/////////////////////////////////////////////////////////////////////////////////////////
//Drawing a square or rectangle
//////////////////////////////////////////////////////////////////////////////////////// 
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
rectangle(250,250,450,400);
getch(); 
}
output of the program will be like this

 //////////////////////////////////////////////////////////////////////////////////////////
//Drawing a eclippse
////////////////////////////////////////////////////////////////////////////////////////// 
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
ellipse(250,250,0,360,100,60);
getch();
}
out put of the program will be like this 

Ok these were some basic shapes now let us draw some objects , please forgave me I am not good at graphics my main aim is to give you some idea to get going . If you want more accurate presentation feel free to modify the code to get your best result

/////////////////////////////////////////////////////////////////////////////////////////
//Diagram of a car
////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
rectangle(100,200,200,250);
rectangle(220,200,320,250);
rectangle(90,190,330,290);

circle(150,290,30);
circle(270,290,30);

getch(); 
}
the output will be like this

//////////////////////////////////////////////////////////////////////////////////////////
 //Diagram of a fish
/////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");

ellipse(150,200,0,360,100,50);
circle(200,195,20);
ellipse(50,200,0,360,50,30);

getch(); 
}

the output will be like this
/////////////////////////////////////////////////////////////////////////////////////////////
 //Diagram of a kite
//////////////////////////////////////////////////////////////////////////////////////////// 
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");

line(220,140,300,140);
line(270,100,270,180);
line(220,140,270,100);
line(220,140,270,180);
line(270,100,300,140);
line(270,180,300,140);

getch();

the output will be like this

So these were some diagrams I made now let us use the same diagrams and do some simple animation on them like moving them on screen


/////////////////////////////////////////////////////////////////////////////////////////////
 //Car Moving
////////////////////////////////////////////////////////////////////////////////////////////

#include<stdio.h>
#include<graphics.h>
void main()
{

int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");

 do{
     for(i=0;i<=500;i++)
     {
       delay(8);
             cleardevice();

rectangle(100+i,200,200+i,250);
rectangle(220+i,200,320+i,250);
rectangle(90+i,190,330+i,290);

circle(150+i,290,30);
circle(270+i,290,30);

      }

   }while(!kbhit());

getch();
}

/////////////////////////////////////////////////////////////////////////////////////////////
 //Fish Moving
////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{

int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");

do{
   for(i=0;i<=500;i++)
   {
     delay(8);
     cleardevice();
ellipse(150+i,200,0,360,100,50);
circle(200+i,195,20);
ellipse(50+i,200,0,360,50,30);

   }
  }while(!kbhit());
getch();
}

////////////////////////////////////////////////////////////////////////////////////////////
//Kite Moving
////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");

do{
   for(i=0;i<=300;i++)
    {
     delay(8);
     cleardevice();
line(220+i,140,300+i,140);
line(270+i,100,270+i,180);
line(220+i,140,270+i,100);
line(220+i,140,270+i,180);
line(270+i,100,300+i,140);
line(270+i,180,300+i,140);
     }
  
       }while(!kbhit());
getch();
}

Ok so we have come to our end but before that lets do a final program to draw the Indian flag and also color it
 ///////////////////////////////////////////////////////////////////////////////////////////////
//Indian Flag
//////////////////////////////////////////////////////////////////////////////////////////////// 


#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");

setfillstyle(LINE_FILL,BLUE);
bar(0,0,800,800);

printf("JAY HIND");

setfillstyle(SOLID_FILL,BROWN);
bar(100,100,300,150);

setfillstyle(SOLID_FILL,WHITE);
bar(100,150,300,200);

setcolor(BLUE);
circle(200,175,25);
line(200,175,200,200);
line(200,175,200,150);
line(200,175,225,175);
line(200,174,174,174);

setfillstyle(SOLID_FILL,GREEN);
bar(100,200,300,250);

setfillstyle(SOLID_FILL,RED);
bar(98,98,100,700);

getch();
 }

the output will be like this

#include<graphics.h>
#include<conio.h>
#include<dos.h>
void main()
{
int gdriver=DETECT,gmode,i=0,j=0;
initgraph(&gdriver,&gmode,”c:\turboc3\bgi”);
for(i;i<420;++i)
{
line(0,245,650,245);
line(0+i,200,210+i,200);
line(50+i,200,70+i,170);
line(70+i,170,140+i,170);
line(140+i,170,160+i,200);
line(85+i,170,85+i,200);
line(125+i,170,125+i,200);
line(0+i,200,0+i,230);
line(210+i,200,210+i,230);
line(0+i,230,50+i,230);
circle(65+i,230,15);
line(80+i,230,130+i,230);
circle(145+i,230,15);
line(210+i,230,160+i,230);
pieslice(65+i,230,359-j,360-j,15);
pieslice(65+i,230,179-j,180-j,15);
pieslice(65+i,230,89-j,90-j,15);
pieslice(65+i,230,269-j,270-j,15);
pieslice(145+i,230,359-j,360-j,15);
pieslice(145+i,230,179-j,180-j,15);
pieslice(145+i,230,89-j,90-j,15);
pieslice(145+i,230,269-j,270-j,15);
if(j==179)
j=0;
++j;
delay(30);
cleardevice();
}
closegraph();
}
Simple program to create a moving car in graphics