CGR Pro
CGR Pro
CGR Pro
Is done by
Is submitted for
For
Of micro project of
Computer Graphics
By
1.0Introduction
Program in C using graphics to move a car. A car is made using two rectangles and two circles
which act as tires of the car. A for loop is used to move the car forward by changing the
rectangle and circle coordinates and erasing the previous contents on screen using clearviewport,
you can also use cleardevice. Speed of car can be adjusted using delay function, more the delay
lesser will be the speed or lesser the delay your car will move fast. In this program color of the
car also keeps on changing, this is accomplished by incrementing the color value by one each
time in the for loop, you can also use random function for this purpose. Before you see a car
moving you will be asked to press a key.
4.0.Resources required
Draw a moving car using computer graphics programming in C:In computer graphics, use
graphics.h which provide direct functions to draw different coordinate shapes (like circle,
rectangle etc). By using these functions we can draw different objects like car, hut, trees etc. In
this program, we will draw a moving car using line and circles.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gm,gd=DETECT;
int i= 0;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
while(i<=800)
line(0,300,800,300); // Path
line(50+i,220,100+i,220);
line(50+i,220,30+i,250);
line(100+i,220,120+i,250);
rectangle(0+i,250,160+i,270);
circle(30+i,285,12);
circle(130+i,285,12);
if(i>=800)
break;
i=i+2;
clearviewport(); // clearing image which would make illusion of moving
car
getch();
closegraph();
Output:
7.0.Skill developed / learing out of this micro-project:
9.0. Conclusion
From this micro-project, We are able to developed programs in computer graphics using C .To
develop various animations like moving car etc.