#include
#include
#include
#include
#include
void main()
{
int gd=DETECT,i,j,gm,B[5][2],A[5][2],A1[5][2],x,y,tx=0,ty=0,sx=0,sy=0,a;
int rf,sh,shx,shy,yr,xr;
float r;
char ch;
ch= 'y';
enter: clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
x=getmaxx();
y=getmaxy();
setlinestyle(0,0,1);
setcolor(WHITE);
line (x/2,0,x/2,y);
line(0,y/2,x,y/2);
putpixel(x/2,y/2, BLACK);
outtextxy(x/2+2,y/2+2,"0");
putpixel(x/2+40,y/2, BLACK); //lits the pixel
outtextxy(x/2+40,y/2+2,"40");
putpixel(x/2+80,y/2, BLACK);
outtextxy(x/2+80,y/2+2,"80");
putpixel(x/2+120,y/2, BLACK);
outtextxy(x/2+120,y/2+2,"120");
putpixel(x/2+160,y/2, BLACK);
outtextxy(x/2+160,y/2+2,"160");
putpixel(x/2+200,y/2, BLACK);
outtextxy(x/2+200,y/2+2,"200");
putpixel(x/2+240,y/2, BLACK);
outtextxy(x/2+240,y/2+2,"240");
putpixel(x/2-40,y/2, BLACK);
outtextxy(x/2-40,y/2+2,"-40");
putpixel(x/2-80,y/2, BLACK);
outtextxy(x/2-80,y/2+2,"-80");
putpixel(x/2-120,y/2, BLACK);
outtextxy(x/2-120,y/2+2,"-120");
putpixel(x/2-160,y/2, BLACK);
outtextxy(x/2-160,y/2+2,"-160");
putpixel(x/2-200,y/2, BLACK);
outtextxy(x/2-200,y/2+2,"-200");
putpixel(x/2-240,y/2, BLACK);
outtextxy(x/2-240,y/2+2,"-240");
putpixel(x/2,y/2+40, BLACK);
outtextxy(x/2,y/2+40,"-40");
putpixel(x/2,y/2+80, BLACK);
outtextxy(x/2,y/2+80,"-80");
putpixel(x/2,y/2+120, BLACK);
outtextxy(x/2,y/2+120,"-120");
putpixel(x/2,y/2+160, BLACK);
outtextxy(x/2,y/2+160,"-160");
putpixel(x/2,y/2+200, BLACK);
outtextxy(x/2,y/2+200,"-200");
putpixel(x/2,y/2+240, BLACK);
outtextxy(x/2,y/2+240,"-240");
putpixel(x/2,y/2-40, BLACK);
outtextxy(x/2+2,y/2-40,"40");
putpixel(x/2,y/2-80, BLACK);
outtextxy(x/2+2,y/2-80,"80");
putpixel(x/2,y/2-120, BLACK);
outtextxy(x/2+2,y/2-120,"120");
putpixel(x/2,y/2-160, BLACK);
outtextxy(x/2+2,y/2-160,"160");
putpixel(x/2,y/2-200, BLACK);
outtextxy(x/2+2,y/2-200,"200");
putpixel(x/2,y/2-240,);
outtextxy(x/2+2,y/2-240,"240");
line(0,y,x,0);
line(0,0,x,y);
printf("\n1:Translation\n2:Scaling\n3:Rotation\n4:Reflection\n 5:Shearin g\nEnter your choice: ");
scanf("%d",&a);
switch(a)
{
case 1:
printf("enter first co-ordinates: ");
scanf(" %d %d",&A[0][0],&A[0][1]);
printf ("enter second co-ordinates: ");
scanf("%d %d",&A[1][0],&A[1][1]);
printf("enter third co-ordinates: ");
scanf("%d %d",&A[2][0],&A[2][1]);
for(i=0;i<3;i++)
{
A[i][0]=x/2+A[i][0];
A[i][1]=y/2-A[i][1];
}
A[3][0]=A[0][0];
A[3][1]=A[0][1];
setcolor(WHITE);
drawpoly(4,*A);
printf("\nEnter tx ty : ");
scanf("%d %d",&tx,&ty);
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<3;i++)
{
B[i][0]=A[i][0]+tx;
B[i][1]=A[i][1]-ty;
}
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
break;
case 2:
printf("enter first co-ordinates: ");
scanf(" %d %d",&A[0][0],&A[0][1]);
printf ("enter second co-ordinates: ");
scanf("%d %d",&A[1][0],&A[1][1]);
printf("enter third co-ordinates: ");
scanf("%d %d",&A[2][0],&A[2][1]);
for(i=0;i<3;i++)
{
A1[i][0]=x/2+A[i][0];
A1[i][1]=y/2-A[i][1];
}
A1[3][0]=A1[0][0];
A1[3][1]=A1[0][1];
setcolor(WHITE);
drawpoly(4,*A1);
printf("\nEnter Sx Sy : ");
scanf("%d %d",&sx,&sy);
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<3;i++)
{
B[i][0]=A[i][0]*sx;
B[i][1]=A[i][1]*sy;
}
for(i=0;i<3;i++)
{
B[i][0]=x/2+B[i][0];
B[i][1]=y/2-B[i][1];
}
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
break;
case 3:
printf("enter first co-ordinates: ");
scanf(" %d %d",&A[0][0],&A[0][1]);
printf ("enter second co-ordinates: ");
scanf("%d %d",&A[1][0],&A[1][1]);
printf("enter third co-ordinates: ");
scanf("%d %d",&A[2][0],&A[2][1]);
for(i=0;i<3;i++)
{
A1[i][0]=x/2+A[i][0];
A1[i][1]=y/2-A[i][1];
}
A1[3][0]=A1[0][0];
A1[3][1]=A1[0][1];
setcolor(WHITE);
drawpoly(4,*A1);
printf("1.Clockwise\n2.Counter clockwise\n");
scanf("%d",&c);
printf("Enter the rotation angle: ");
scanf("%f",&r);
r= r*3.14/180;
if (c==2)
{
for(i=0;i<3;i++)
{
B[i][0]=x/2+(A[i][0]*cos(r)-A[i][1]*sin(r));
B[i][1]=y/2-(A[i][0]*sin(r)+A[i][1]*cos(r));
}
setlinestyle(1,0,1);
setcolor(WHITE);
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
}
else if (c==1)
{
for(i=0;i<3;i++)
{
B[i][0]=x/2+(A[i][0]*cos(r)+A[i][1]*sin(r));
B[i][1]=y/2-(A[i][1]*cos(r)-A[i][0]*sin(r));
}
setlinestyle(1,0,1);
setcolor(WHITE);
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
}
break;
case 4:
printf("enter first co-ordinates: ");
scanf(" %d %d",&A[0][0],&A[0][1]);
printf ("enter second co-ordinates: ");
scanf("%d %d",&A[1][0],&A[1][1]);
printf("enter third co-ordinates: ");
scanf("%d %d",&A[2][0],&A[2][1]);
for(i=0;i<3;i++)
{
A1[i][0]=x/2+A[i][0];
A1[i][1]=y/2-A[i][1];
}
A1[3][0]=A1[0][0];
A1[3][1]=A1[0][1];
setcolor(WHITE);
drawpoly(4,*A1);
printf("Reflection along\n1.X-axis\n2.Y-axis\n3.Origin\n4.Line y=x\n5.Line y=-x \n");
scanf("%d",&rf);
if(rf==1)
{
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<3;i++)
{
B[i][0]=A1[i][0];
B[i][1]=y/2+A[i][1];
}
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
}
else if(rf==2)
{
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<3;i++)
{
B[i][0]=x/2-A[i][0];
B[i][1]=A1[i][1];
}
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
}
else if(rf==3)
{
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<3;i++)
{
B[i][0]=x/2-A[i][0];
B[i][1]=y/2+A[i][1];
}
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
}
else if(rf==4)
{
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<3;i++)
{
B[i][0]=x/2+A[i][1];
B[i][1]=y/2-A[i][0];
}
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
}
else if(rf==5)
{
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<3;i++)
{
B[i][0]=x/2-A[i][1];
B[i][1]=y/2+A[i][0];
}
B[3][0]=B[0][0];
B[3][1]=B[0][1];
drawpoly(4,*B);
}
break;
case 5:
printf("enter first co-ordinates: ");
scanf(" %d %d",&A[0][0],&A[0][1]);
printf ("enter second co-ordinates: ");
scanf("%d %d",&A[1][0],&A[1][1]);
printf("enter third co-ordinates: ");
scanf("%d %d",&A[2][0],&A[2][1]);
printf("enter fourth co-ordinates: ");
scanf("%d %d",&A[3][0],&A[3][1]);
for(i=0;i<4;i++)
{
A1[i][0]=x/2+A[i][0];
A1[i][1]=y/2-A[i][1];
}
A1[4][0]=A1[0][0];
A1[4][1]=A1[0][1];
setcolor(WHITE);
drawpoly(5,*A1);
printf("1.X-shear\n2.Y-shear\n3.X-shear with Yref\n4.Y-shearwith X-ref \n");
scanf("%d",&sh);
if (sh==1)
{
printf("\nEnter shx :");
scanf("%d",&shx);
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<4;i++)
{
B[i][0]=x/2+(A[i][0]+(A[i][1]*shx));
B[i][1]=A1[i][1];
}
B[4][0]=B[0][0];
B[4][1]=B[0][1];
drawpoly(5,*B);
}
else if(sh==2)
{
printf("\nEnter shy :");
scanf("%d",­);
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<4;i++)
{
B[i][1]=y/2-(A[i][1]+(A[i][0]*shy));
B[i][0]=A1[i][0];
}
B[4][0]=B[0][0];
B[4][1]=B[0][1];
drawpoly(5,*B);
}
else if(sh==3)
{
printf("\nEnter shx and Y-ref: ");
scanf("%d %d",&shx,&yr);
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<4;i++)
{
B[i][0]=x/2+(A[i][0]+(A[i][1]*shx)-(shx*yr));
B[i][1]=A1[i][1];
}
B[4][0]=B[0][0];
B[4][1]=B[0][1];
drawpoly(5,*B);
}
else if(sh==4)
{
printf("\nEnter shy and X-ref: ");
scanf("%d %d",­,&xr);
setlinestyle(1,0,1);
setcolor(WHITE);
for(i=0;i<4;i++)
{
B[i][1]=y/2-((A[i][0]*shy)+A[i][1]-(shy*xr));
B[i][0]=A1[i][0];
}
B[4][0]=B[0][0];
B[4][1]=B[0][1];
drawpoly(5,*B);
}
break;
default:
printf("\nEnter a valid choice ");
goto enter;
}
printf("Do u want to continue? y/n ");
scanf("%s",&ch);
if(ch=='y')
{
goto enter;
}
getch();
closegraph();
restorecrtmode();
}
No comments:
Post a Comment