Sunday, 19 October 2014

Reflection Transformation

This Code Is One Of The Most Simplified Codes For Reflection Transformation In C++

Functions Used:
  1. getmaxx(); = is used for getting maximum value of the x co ordinate of the output screen.
  2. getmaxy(); = is used for getting maximum value of the y co ordinate of the output screen.

Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gd=DETECT,gm,xmax,ymax,xmid,ymid,x,y,x1,y1,a;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
xmax=getmaxx();
ymax=getmaxy();
xmid=xmax/2;
ymid=ymax/2;
setcolor(WHITE);
line(0,ymid,xmax,ymid);
line(xmid,0,xmid,ymax);
cout<<"Enter the co-ordinates of the edges\n x-coordinate: ";
cin>>x1;
cout<<" y-coordinate: ";
cin>>y1;
x=xmid+x1;
y=ymid-y1;
line(xmid,ymid,x,ymid);
line(x,ymid,x,y);
line(x,y,xmid,y);
line(xmid,y,xmid,ymid);
cout<<"Enter any one reflection options:\n1.X-axis\n2.Y-axis\n";
cin>>a;
setcolor(RED);
if(a==1)
{
y=ymid+y1;
line(xmid,ymid,x,ymid);
line(x,ymid,x,y);
line(x,y,xmid,y);
line(xmid,y,xmid,ymid);
}
if(a==2)
{
x=xmid-x1;
line(xmid,ymid,x,ymid);
line(x,ymid,x,y);
line(x,y,xmid,y);
line(xmid,y,xmid,ymid);
}
else
cout<<"enter a valid no.";
getch();
}
Output:


No comments:

Post a Comment