This Code Is One Of The Most Simplified Codes For Shear Transformation In C++
Functions Used:- getmaxx(); = is used for getting maximum value of the x co ordinate of the output screen.
- 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()
{
int gd=DETECT,gm,x,y,x1,y1,sh,a;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
int xmax=getmaxx();
int ymax=getmaxy();
int midx=xmax/2;
int midy=ymax/2;
setcolor(WHITE);
line(0,midy,xmax,midy); //x axis;
line(midx,0,midx,ymax); //y axis
cout<<"enter x co-ordinate of the edges: ";
cin>>x1;
cout<<"Enter y co-ordinate of the edges: ";
cin>>y1;
x=x1+midx;
y=-y1+midy;
line(midx,midy,x,midy);
line(x,midy,x,y);
line(x,y,midx,y);
line(midx,y,midx,midy);
cout<<"the shearing is to be done in?\n enter\n 1for +ve xaxis\n";
cout<<" 2 for -ve xaxis\n 3 for +ve yaxis\n 4 for -ve y axis\n";
cin>>a;
cout<<"Enter the value of shearing factor\n sh=";
cin>>sh;
setcolor(RED);
if(a==1)
{
line(midx,midy,x,midy);
line(x,midy,x+sh,y);
line(x+sh,y,midx+sh,y);
line(midx+sh,y,midx,midy);
}
if(a==2)
{
line(midx,midy,x,midy);
line(x,midy,x-sh,y);
line(x-sh,y,midx-sh,y);
line(midx-sh,y,midx,midy);
}
if(a==3)
{
line(midx,midy,x,midy-sh);
line(x,midy-sh,x,y-sh);
line(x,y-sh,midx,y);
line(midx,y,midx,midy);
}
if(a==4)
{
line(midx,midy,x,midy+sh);
line(x,midy+sh,x,y+sh);
line(x,y+sh,midx,y);
line(midx,y,midx,midy);
}
getch();
}
Output:
No comments:
Post a Comment