Google Ads

Monday, May 18, 2009

2D TRANSLATION Program

include files
stdio.h
conio.h
graphics.h
math.h
stdlib.h
int n,i,k,j,x[10],y[10],tx,ty;
void drawpolygen(int x[10]);
void main()
{
int gdriver = DETECT, gmode, e0rrorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
clrscr();
printf("enter the no of edges");
scanf("%d",&n);
if(n< 3)
{
printf("The polygons does not exit");
}
k=2*n;
printf("Enter the coordinatines");
for(i=0;i< k;i++)
{
scanf("%d",&x[i]);
}
drawpolygen(x);
printf("Enter the coordinates");
scanf("%d%d",&tx,&ty);
for(i=0;i< k;i++)
{
if(i%2==1)
{
x[i]=x[i]+ty;
}
else
{
x[i]=x[i]+tx;
}
}
drawpolygen(x);
getch();
}
void drawpolygen(int x[10])
{
for(i=0;i< =k/2;i+=2)
{
line(x[i],x[i+1],x[i+2],x[i+3]);

}
line(x[k-2],x[k-1],x[0],x[1]);
}

No comments:

Post a Comment