Reflect an object as per user’s choice. Choices are With respect to x – axis, With respect to y – axis, With respect to co-ordinate origin and With respect to an axis at 45 degree to x – axis.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
void Triangle(int, int, int, int, int, int);
int midx=319, midy=239;
void main()
{
int gdriver=DETECT, gmode, c,r,x1,y1,x2,y2,x3,y3;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
do
{
clrscr();
cleardevice();
printf("1.X-Axis \n2.Y-Axis \n3.Co-ordinate Origin \n4.An Axis 45-Degree to X-Axis \n\n");
printf("Enter the choice : ");
scanf("%d",&c);
if(c==5)
exit(0);
clrscr();
cleardevice();
printf("Enter the value of (x1,y1) : ");
scanf("%d %d",&x1,&y1);
printf("Enter the value of (x2,y2) : ");
scanf("%d %d",&x2,&y2);
printf("Enter the value of (x3,y3) : ");
scanf("%d %d",&x3,&y3);
cleardevice();
line(0,midy,2*midx,midy);
line(midx,0,midx,2*midy);
Triangle(x1,y1,x2,y2,x3,y3);
switch(c)
{
case 1:
getch(); setcolor(4);
Triangle(x1,-y1,x2,-y2,x3,-y3);
break;
case 2:
getch(); setcolor(4);
Triangle(-x1,y1,-x2,y2,-x3,y3);
break;
case 3:
getch(); setcolor(4);
Triangle(-x1,-y1,-x2,-y2,-x3,-y3);
break;
case 4:
getch(); setcolor(4);
Triangle(y1,x1,y2,x2,y3,x3);
break;
// case 5: exit(0);
}
printf("Do you want to continue...");
}while(getch() != 'n');
closegraph();
}
void Triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
line(midx+x1,midy-y1,midx+x2,midy-y2);
line(midx+x2,midy-y2,midx+x3,midy-y3);
line(midx+x3,midy-y3,midx+x1,midy-y1);
}