Simple program to create a moving car in graphics

Simple program to create a moving car in graphics
#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();
}

33 thoughts on “Simple program to create a moving car in graphics

  1. Muhamad Syafiee

    when I try to run at borland 5.02, it say "#error BGI graphics not supported under Windows"

    what the function of "c:\turboc3\bgi"?

    Reply
    1. Neeraj Mishra

      Hello Mauhamad
      It is the path of the bgi folder which contains the necessary files to run graphics program. This is different for different compilers, just change path "c:\turboc3\bgi" to correct bgi folder path and the error will be removed.
      If you have further queries than let me know.

      Reply
      1. Athul

        this program doesn’t execute it shows error in the initgraph(&gdriver,&gmode,”c:\turboc3\bgi”); part.
        it shows undefined symbol “c”, and error in the symbol of \

        Reply
  2. Subhadeep Dey

    I am using Turbo C++ 4.5 in Windows 7 and whenever I tried to run this program, it said "BGI Graphics not supported under Windows". What should I do?

    Reply
    1. Neeraj Mishra

      Yes you are right bro, this will not work in linux as GCC does not have dos.h and conio.h. You can try there alternatives by searching on google. I can't help you in this case because i have very less experience of working on GCC.

      Reply
  3. muneeb memon

    bro i want some help in C programming can u plzzz help me this is my email muneebmemon5@gmail or can u give me your email i have some questions to ask about C thankx

    Reply
  4. Sohail Nazar

    we have error of graphics.h header file
    1>d:programmingc sharpemovingcarmovingcarsource.cpp(3): fatal error C1083: Cannot open include file: 'graphics.h': No such file or directory

    Reply
    1. Neeraj Mishra

      Hello,
      It is the path of the bgi folder which contains the necessary files to run graphics program.
      If you have further queries than let me know.

      Reply
  5. Prince kumar

    I am a beginner so please make me understand this line(0,245,650,245)

    Reply
  6. cally

    can someone explain me the car program?????
    #include
    #include
    #include

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

    initgraph(&gd,&gm,”C:\\TC\\BGI”);

    settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
    outtextxy(25,240,”Press any key to view the moving car”);

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

    for( i = 0 ; i <= 420 ; i = i + 10, j++ )
    {
    rectangle(50+i,275,150+i,400);
    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;
    }

    Reply
  7. krrish

    code run but screen doesn’t hold i use getch() but didn’t work
    so what i do help me

    Reply
  8. Vathsala

    Hi, it’s interesting to see that someone has so much love for programming. Keep up the good work.

    By the way, can your code make the car move? Have you also implemented similar program in Java?

    Thank you.

    Reply
  9. VANAK

    It not Run! I Can’t RUN with my Turmbo C++ . why brother please tel me ?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *