Monday, October 25, 2010

computer graphics lab



//PROGRAM TO DRAW A CAR

#include
#include
#define round(x) ((int)(x+0.5))
void parametric(int x,int y)
{ int i;
float r=40,x2,y2;
for(i=180;i<360;i++)
{
x2=(float)(x)+r*cos((i*3.1415)/180);
y2=(float)(y)+r*sin((i*3.1415)/180);
putpixel(round(x2),round(y2),15);
}
}
void car()
{
int x1=0,x2=20,x3=40,x4=50,x5=60,x6=70,x7=100,x8=120,x9=130,x10=180,x11=200,x12=205,x13=210,x14=220,x15=240,x16=260,x17=300;
while(x17<600)
{
cleardevice();
line(x1,250,x1,350);
line(x1,350,x3,350);
line(x1,250,x3,150);
line(x2,250,x4,250);
line(x2,250,x4,175);
line(x4,250,x4,175);
line(x5,250,x5,175);
circle(x6,350,38);
circle(x6,350,25);
parametric(x6,350);
line(0,388,650,388);
line(x5,175,x8,175);
line(x5,250,x8,250);
line(x8,175,x8,250);
line(x9,175,x9,250);
line(x9,175,x11,175);
line(x9,250,x11,250);
line(x11,175,x11,250);
line(x7,350,x10,350);
line(x12,175,x12,250);
line(x12,175,x15,250);
line(x12,250,x15,250);
line(x3,150,x14,150);
line(x14,150,x16,225);
circle(x13,350,38);
circle(x13,350,25);
parametric(x13,350);
line(x16,225,x17,250);
line(x15,350,x17,350);
line(x17,250,x17,350);
delay(20);
x1++; x2++;x3++;x4++;x5++; x6++; x7++; x8++; x9++; x10++; x11++; x12++; x13++;
x14++; x15++; x16++; x17++;
}
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"..//bgi");
car();
getch();
}

No comments: