Anda di halaman 1dari 7

Name:- Abhinay pandey

Section k3002
Rollno:- A16
Regno:- 11009176
#include<iostream.h>
#include<process.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void translate(int,int,int,int,int,int,int,int);
void scale(int,int,int,int,int,int,int,int);
void reflect(int,int,int,int,int,int,int,int);
void shearing(int,int,int,int,int,int,int,int);
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:/tc/bgi");
cout<<"enter vertices of rectangle";
int x1,y1,x2,y2,x3,y3,x4,y4;
cin>>x1>>y1>>x2>>y2;
x3=x1+40;y3=y1+40;x4=x2+40;y4=y2+40;
rectangle(x1,y1,x2,y2);
rectangle(x3,y3,x4,y4);
line(x1,y1,x3,y3);
line(x2,y1,x4,y3);
line(x1,y2,x3,y4);
line(x2,y2,x4,y4);
int opt;

cout<<"press 1 for translate\n";


cout<<"press 2 for scaling\n";
cout<<"press 3 for reflect\n";
cout<<"press 4 for shearing\n";
cout<<"press 0 to exit";

while(1)
{
outtextxy(500,0,"enter your choice :");
cin>>opt;
switch (opt)
{
case 1:
translate(x1,y1,x2,y2,x3,y3,x4,y4);
break;
case 2:
scale(x1,y1,x2,y2,x3,y3,x4,y4);
break;
case 3:
reflect(x1,y1,x2,y2,x3,y3,x4,y4);
break;
case 4:
shearing(x1,y1,x2,y2,x3,y3,x4,y4);
break;
case 0:
exit(0);

}
}
getch();

void translate(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int x5,y5,x6,y6,x7,y7,x8,y8,tx,ty;
clrscr();
cout<<"enter tx and ty ";
cin>>tx>>ty;
x5=x1+tx;y5=y1+ty;
x6=x2+tx;y6=y2+ty;
x7=x3+tx;y7=y3+ty;
x8=x4+tx;y8=y4+ty;
rectangle(x5,y5,x6,y6);
rectangle(x7,y7,x8,y8);
line(x5,y5,x7,y7);
line(x6,y5,x8,y7);
line(x5,y6,x7,y8);
line(x6,y6,x8,y8);

void scale(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int sx,sy;
clrscr();
int x5,y5,x6,y6,x7,y7,x8,y8,tx,ty;
cout<<"enter Sx and Sy :";
cin>>sx>>sy;
x5=x1*sx;y5=y1*sy;
x6=x2*sx;y6=y2*sy;
x7=x3*sx;y7=y3*sy;
x8=x4*sx;y8=y4*sy;
rectangle(x5,y5,x6,y6);
rectangle(x7,y7,x8,y8);
line(x5,y5,x7,y7);
line(x6,y5,x8,y7);
line(x5,y6,x7,y8);
line(x6,y6,x8,y8);

void shearing(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int x5,y5,x6,y6,x7,y7,x8,y8,shx;
cout<<"enter Shx :";

cin>>shx;
x5=x1+shx*y1;y5=y1;
x6=x2+shx*y2;y6=y2;
x7=x3+shx*y3;y7=y3;
x8=x4+shx*y4;y8=y4;
rectangle(x5,y5,x6,y6);
rectangle(x7,y7,x8,y8);
line(x5,y5,x7,y7);
line(x6,y5,x8,y7);
line(x5,y6,x7,y8);
line(x6,y6,x8,y8);

void reflect(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int sx,sy;
clrscr();
int x5,y5,x6,y6,x7,y7,x8,y8,tx,ty;
cout<<"reflection along x axis";
int xmax=getmaxx(),ymax=getmaxy();
/* line(xmax/2,0,xmax/2,ymax);
line(0,ymax/2,xmax,ymax/2);
x1=x1+xmax/2;y1=y1+ymax/2;

x2=x2+xmax/2;y2=y2+ymax/2;
x3=x3+xmax/2;y3=y3+ymax/2;
x2=x4+xmax/2;y4=y4+ymax/2;

rectangle(x1,y1,x2,y2);
rectangle(x3,y3,x4,y4);
line(x1,y1,x3,y3);
line(x2,y1,x4,y3);
line(x1,y2,x3,y4);
line(x2,y2,x4,y4); */

x5=x1;y5=ymax/2-y1;
x6=x2;y6=ymax/2-y2;
x7=x3;y7=ymax/2-y3;
x8=x4;y8=ymax/2-y4;
rectangle(x5,y5,x6,y6);
rectangle(x7,y7,x8,y8);
line(x5,y5,x7,y7);
line(x6,y5,x8,y7);
line(x5,y6,x7,y8);
line(x6,y6,x8,y8);

Anda mungkin juga menyukai