How to crerate and move a bus in C
In this article I will show how to use the simple functions of graphics which makes our program more attractive. The function I am going to use are Line, Circle, delay and closegraph. With the help of these functions I am making a moving bus.
Header files we use while writing the code for a moving Bus.
#include stdio.h
#include conio.h
#include dos.h
#include graphics.h
#include stdlib.h
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int i;
from here we enter in the graphic mode
initgraph(&gdriver, &gmode, "c:/TC/BGI");
This is the main code which is inside the for loop used for the creation of bus. I used for loop for moving it from one position to another here I simply change the x-coordinate of the bus and with the increment of one point. So when it changes its coordinate fast it seems to be moving.
for(i=0;i<450;i++)
{
cleardevice();
line(30+i,100,110+i,100);
line(110+i,100,130+i,120);
line(130+i,120,130+i,150);
line(30+i,150,50+i,150);
line(60+i,150,100+i,150);
line(110+i,150,130+i,150);
line(30+i,100,30+i,150);
line(30+i,105,114+i,105);
line(30+i,115,124+i,115);
circle(55+i,150,5); // Back tyres of bus
circle(55+i,150,2);
circle(105+i,150,5); // Front tyres of bus
circle(105+i,150,2);
outtextxy(35+i,130, " X Travels");
delay(20); //control the bus speed by increasing or decreasing the value
}
/* clean up */
getch();
closegraph();
now with the function closegraph we are out from the graphic mode
return 0;
}
This is simple moving bus by using simple
functions like line and circle and you can
improve by adding some more function
and make it more impressive.
am BCA student and now i am learning C . this code is really help full to me .thanks for the share
please try to contribute more things about C programming