Wednesday 22 July 2015

C program for a moving car

C Program for a Moving Car


This program shows a moving car with a color changing effect as the car moves, Save the program as .C and run it. You can also customize it, try modifying the code and have fun :)
Please note that the path in the initgraph() function must be changed as per you directories.
Output images for an instance are shown:

Computer Graphics, C program for a moving car
Computer Graphics, C program for a moving car


Here's the tiny code ;)

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

void main()
{
   int i, j = 0, gd = DETECT, gm;

   initgraph(&gd,&gm,"C:\\TurboC3\\BGI");


   settextstyle(DEFAULT_FONT,HORIZ_DIR,2);

   outtextxy(25,240,"Press any key to view the moving Vehicle");

   getch();

   setviewport(0,0,639,440,1);

   for( i = 0 ; i <= 420 ; i = i + 10, j++ )

   {
      rectangle(50+i,275,150+i,400);
      outtextxy(i+52,295,"Shadow");
      outtextxy(i+62,325,"Hack");
      rectangle(150+i,350,200+i,400);
      circle(75+i,410,10);
      circle(175+i,410,10);
      setcolor(j);
      delay(100);

      if( i == 420 )

break;
      clearviewport();
   }

   getch();

   closegraph();
   return 0;
}

No comments:

Post a Comment