Graphic program to design a moving car:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
void car_body(int,int);
void car_body1(int,int);
void car_body2(int,int);
void car_body3(int,int);
void front_tyre(int,int,int,int);
void rear_tyre(int,int,int,int);
void tyre_rotation(int,int,int,int,int);
int gd=0,gm,poly_cord[34],p1[4],p2[4],p3[4],midx,midy,i,k,j,r,x,y,mid,angle1,angle2;
void main()
{
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
randomize();
//midx=getmaxx()/2;
midx=random(319);
midx+=320;
mid=midx;
midy=getmaxy()/2;
k=0;
while(mid>=0)
{
k++;
car_body(midx-2*k,midy);
car_body(midx-2*k,midy-1);
car_body(midx-2*k,midy-2);
car_body(midx-2*k,midy-3);
car_body1(midx-2*k,midy);
car_body1(midx-2*k,midy-1);
car_body1(midx-2*k,midy-2);
car_body1(midx-2*k,midy-3);
car_body2(midx-2*k,midy);
car_body3(midx-2*k,midy);
if(k%2!=0)
{
angle1=0;
angle2=angle1+30;
}
else
{
angle1=15;
angle2=angle1+30;
}
front_tyre(midx-2*k,midy,angle1,angle2);
rear_tyre(midx-2*k,midy,angle1,angle2);
mid=midx-2*k;
}
}
//****************************************************
void car_body(int midx,int midy)
{
/*
*
*/
poly_cord[0]=midx-200;
poly_cord[1]=midy;
/*
*-------*
*/
poly_cord[2]=midx-120;
poly_cord[3]=midy;
/* *
/
*-------*
*/
poly_cord[4]=midx-100;
poly_cord[5]=midy-60;
/* *--------------*
/
*-------*
*/
poly_cord[6]=midx+100;
poly_cord[7]=midy-60;
/* *--------------*
/ \
*-------* *
*/
poly_cord[8]=midx+120;
poly_cord[9]=midy;
/* *--------------*
/ \
*-------* *-------*
*/
poly_cord[10]=midx+200;
poly_cord[11]=midy;
/* *--------------*
/ \
*-------* *-------*
|
*
*/
poly_cord[12]=midx+200;
poly_cord[13]=midy+40;
/* *--------------*
/ \
*-------* *-------*
|
*----*
*/
poly_cord[14]=midx+140;
poly_cord[15]=midy+40;
/* *--------------*
/ \
*-------* *-------*
|
* |
| |
*----*
*/
poly_cord[16]=midx+140;
poly_cord[17]=midy+20;
/* *--------------*
/ \
*-------* *-------*
|
*----* |
| |
*----*
*/
poly_cord[18]=midx+80;
poly_cord[19]=midy+20;
/* *--------------*
/ \
*-------* *-------*
|
*----* |
| | |
* *----*
*/
poly_cord[20]=midx+80;
poly_cord[21]=midy+30;
/* *--------------*
/ \
*-------* *-------*
|
*----* |
| | |
*---------* *----*
*/
poly_cord[22]=midx-80;
poly_cord[23]=midy+30;
/* *--------------*
/ \
*-------* *-------*
|
* *-----* |
| | | |
*--------* *----*
*/
poly_cord[24]=midx-80;
poly_cord[25]=midy+20;
/* *--------------*
/ \
*-------* *-------*
|
*-----* *-----* |
| | | |
*--------* *----*
*/
poly_cord[26]=midx-140;
poly_cord[27]=midy+20;
/* *--------------*
/ \
*-------* *-------*
|
*-----* *-----* |
| | | | |
* *--------* *----*
*/
poly_cord[28]=midx-140;
poly_cord[29]=midy+40;
/* *--------------*
/ \
*-------* *-------*
|
*-----* *-----* |
| | | | |
*----* *--------* *----*
*/
poly_cord[30]=midx-200;
poly_cord[31]=midy+40;
/* *--------------*
/ \
/ \
/ \
*-------* *-------*
| |
| *-----* *-----* |
| | | | | |
*-----* *------------------* *-----*
*/
poly_cord[32]=midx-200;
poly_cord[33]=midy;
drawpoly(17,poly_cord);
}
void front_tyre(int midx,int midy,int angle1,int angle2)
{
x=(midx-(140+80)/2);
y=(midy+60);
r=30;
tyre_rotation(x,y,r,angle1,angle2);
}
void rear_tyre(int midx,int midy,int angle1,int angle2)
{
x=(midx+(140+80)/2);
y=(midy+60);
r=30;
tyre_rotation(x,y,r,angle1,angle2);
}
void tyre_rotation(int x,int y,int r,int angle1,int angle2)
{
int t;
car_body(midx-2*k,midy);
circle(x,y,r);
circle(x,y,r-1);
circle(x,y,r-2);
circle(x,y,r-3);
circle(x,y,r-4);
circle(x,y,r-5);
circle(x,y,r-6);
t=360;
do
{
setfillstyle(2,0);
pieslice(x,y,angle1,angle2,r-8);
angle1=angle2+2;
angle2=angle2+15;
t=t-15;
}
while(t>=0);
cleardevice();
}
void car_body1(int midx,int midy)
{
p1[0]=midx-120;
p1[1]=midy;
p1[2]=midx+120;
p1[3]=midy;
drawpoly(2,p1);
}
void car_body2(int midx,int midy)
{
p2[0]=midx-70;
p2[1]=midy;
p2[2]=midx-70;
p2[3]=midy-60;
drawpoly(2,p2);
}
void car_body3(int midx,int midy)
{
p3[0]=midx+70;
p3[1]=midy;
p3[2]=midx+70;
p3[3]=midy-60;
drawpoly(2,p3);
}