Saturday, 18 October 2014

Scaling Transformation

This Code Is One Of The Most Simplified Codes For

Scaling Transformation In C++


Functions Used:
  1. getmaxx(); for getting maximum value of x axis of the screen.
  2. getmaxy(); for getting maximum value of y axis of the screen.
Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gm,gd=DETECT,maxx,maxy,midx,midy,x1,y1,x,y,scx,scy;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
setcolor(WHITE);
line(0,midy,maxx,midy);
line(midx,0,midx,maxx);
cout<<"enter the \nx co-ordinate of the edges: ";
cin>>x1;
cout<<"y co-ordinate of the edges: ";
cin>>y1;
x=midx+x1;
y=midy-y1;
line(midx,midy,x,midy);
line(x,midy,x,y);
line(x,y,midx,y);
line(midx,y,midx,midy);
cout<<"enter scaling factors ";
cout<<"\nsc x: ";
cin>>scx;
cout<<"sc y: ";
cin>>scy;
x=midx+(scx*x1);
y=midy-(scy*y1);
setcolor(RED);
line(midx,midy,x,midy);
line(x,midy,x,y);
line(x,y,midx,y);
line(midx,y,midx,midy);
getch();
}
Output:


No comments:

Post a Comment