Google Ads

Monday, May 18, 2009

2D SCALING Program

include files
stdio.h
graphics.h
stdlib.h

math.h
int x[10],n,i,sx,sy,xf,yf,k;
void drawpolygon(int x[10]);
int main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}

printf("Enter the values of n");
scanf("%d",&n);
if(n< 3)
{
printf("NO polygon");
}
k=2*n;
for(i=0;i< k;i++)
{
printf("Enter the values");
scanf("%d",&x[i]);
}
drawpolygon(x);
printf("Enter the values sx");
scanf("%d",&sx);
printf("Enter the values sy");
scanf("%d",&sy);
printf("Enter the reference point");
scanf("%d%d",&xf,&yf);
for(i=0;i< k;i++)
{
if(i%2==1)
{
x[i]=x[i]*sy+yf*(1-sy);
}
else
{
x[i]=x[i]*sx+xf*(1-sx);
}
}
drawpolygon(x);
getch();
}

void drawpolygon(int x[10])
{
int i,j;
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