Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
#include<conio.h> int x1,x2,x3,y1,y2,y3,t,tx,sx,sy,shx,shy,ch; float rx1,rx2,rx3,ry1,ry2,ry3; float ang,theta; int main(void) { int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode,"C:\\TC\\BGI"); errorcode = graphresult(); if(errorcode != grOk) { /* if error occours*/ /* request for auto detection*/
printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); } else {
do
printf("\n1.Translation\n2.Reflection\n3.Rotation\n4.Scaling\n5.Shearing\n"); printf("\nEnter Your choice"); /* get the choice from the user*/ scanf("%d",&ch); switch(ch) { case 1:
printf("\n Enter all coordinates values :"); /* get the coordinate values*/ scanf("%d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3);
printf("\n Enter the value tranlsation factor :"); scanf("%d",&tx); /* get the value for the translation factor*/ printf("\n After Translation\n ");
line(x1+tx,y1,x2+tx,y2); /* draw the new translated image*/ line(x2+tx,y2,x3+tx,y3); line(x3+tx,y3,x1+tx,y1); break; case 2: printf("\n Enter all coordinates values :");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
printf("\n Before Reflection "); /* draw the image before reflection*/ line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
printf("\n After Reflection "); line(x1,y1+10+(2*t),x2,y2+10); /* draw the reflected object*/ line(x2,y2+10,x3,y3+10); line(x3,y3+10,x1,y1+10+(2*t)); break; case 3: printf("\n Enter all coordinates values :");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); printf("\n Before Rotation "); /* get the original coordinates*/ line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1);
printf("\n Enter the rotation angle :"); /* get the angle for rotation*/ scanf("%f",&ang);
line(rx2,ry2,rx3,ry3); line(rx3,ry3,rx1,ry1); break; case 4: printf("\n Enter all coordinates values :");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); printf("\n Before Scaling "); /* get the scale factor*/ line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1);
printf("\n After Scaling "); /* draw the object after scaling*/ line(x1+sx,y1+sy,x2+sx,y2+sy); line(x2+sx,y2+sy,x3+sx,y3+sy); line(x3+sx,y3+sy,x1+sx,y1+sy);
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); printf("\n Before Shearing "); /* get the values for shearing*/ line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
if(ch==0) {
exit(0); break;
} } while(ch!=0); } getch();