# Moving a Stationary Car

We are going to talk about "how we can move a stationary car in c-graphics programming." Sounds nice, Right .So go through the following code to learn this interesting concept:

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

main()

{

int i, gd=DETECT,gm;

initgraph(&gd,&gm,"");

setcolor(RED);/*set the color of car to red.*/

rectangle(30,240,130,365);/*draw rectangle make upper part of car*/

rectangle(130,335,180,365);/*draw rectangle make upper part of car*/

circle(55,375,10);/*draw circle make right tire of car*/

circle(155,375,10);/*draw circle make left tire of car*/

outtextxy(30,400,"Press any key to move the car");

getch();

for(i=0;i<=400;i=i+20)/*using for loop for moving car in forward direction*/

{

rectangle(30+i,240,130+i,365);

rectangle(130+i,335,180+i,365);

circle(55+i,375,10);

circle(155+i,375,10);

delay(100);/* delay function is used here to maintain the speed of the car*/

if(i==400)

break;

cleardevice();

}

getch();

closegraph();

return 0;

}

In the above source code a car has been made using two rectangles and two circles. In which rectangles works as upper body of car and circle works like the tires of the car. We are moving the car in forward direction with the help of 'for loop' by changing the coordinates of circle and rectangle and erasing the previous contents on screen using cleardevice() function. delay() function is used here to maintain the speed of the car. You can run the above code in TurboC compiler. We can't show you moving car here but the car will look like as follows: