#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>

int drawhouse(float hx[],float hy[])
{  int i;
   int cx=getmaxx()/2;
   int cy=getmaxy()/2;
   for(i=0;i<4;i++)
       line(cx+hx[i],cy-hy[i],cx+hx[i+1],cy-hy[i+1]);
   line(cx+hx[4],cy-hy[4],cx+hx[0],cy-hy[0]);
}
void initscreen(float hx[],float hy[])
{  line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
   line(getmaxx()/2,0,getmaxx()/2,getmaxy());
   drawhouse(hx,hy);
}

void main()
{       int gd=DETECT,gm,ch,i,px,py,lx1,lx2,ly1,ly2;
   float sx,sy,mx,my,x,y,m,c,thx[5],thy[5];
   float hx[]={40.0,10.0,10.0,70.0,70.0};
   float hy[]={80.0,50.0,10.0,10.0,50.0};
   initgraph(&gd,&gm,"c:\tc");
   initscreen(hx,hy);
   do
   {    printf("\nEnter the choice from below");
       printf("\n1.Scale wrt 0,0");
       printf("\n2.Scale wrt arb pt");
       printf("\n3.reflect abt pt");
       printf("\n4.exit");
       scanf("%d",&ch);
       switch(ch)
       {    case 1: cleardevice();
               initscreen(hx,hy);
               for(i=0;i<=4;i++)
               {    thx[i]=hx[i];
                   thy[i]=hy[i];
               }
               printf("\nEnter the scale value of x and y axis");
               scanf("%f%f",&sx,&sy);
               for(i=0;i<=4;i++)
               {       thx[i]=thx[i]*sx;
                   thy[i]=thy[i]*sy;
               }
               drawhouse(thx,thy);
               break;

           case 2: cleardevice();
               initscreen(hx,hy);
               for(i=0;i<=4;i++)
               {    thx[i]=hx[i];
                   thy[i]=hy[i];
               }
               printf("\nEnter the ref point");
               scanf("%d%d",&px,&py);
               printf("\nEnter the scale value of x and y axis");
               scanf("%f%f",&sx,&sy);
               for(i=0;i<=4;i++)
               {       thx[i]-=px;
                   thy[i]-=py;
               }
               for(i=0;i<=4;i++)
               {       thx[i]=thx[i]*sx;
                   thy[i]=thy[i]*sy;
               }
               for(i=0;i<=4;i++)
               {       thx[i]+=px;
                   thy[i]+=py;
               }
               drawhouse(thx,thy);
               break;

           case 3: cleardevice();
               initscreen(hx,hy);
               printf("\nEnter the line with m amd c value");
               scanf("%f%f",&m,&c);
               if(m>0||m<0)
               {    lx1=0;
                   ly1=c;
                   lx2=(getmaxy()-c)/m;
                   ly2=getmaxy();
               }
               if(m==0)
               {       lx1=0;
                   ly1=c;
                   lx2=getmaxx();
                   ly2=c;
               }
               if(m>=9999)
               {       lx1=lx2=c;
                   ly1=0;
                   ly2=getmaxy();
               }
               for(i=0;i<=4;i++)
               {       thx[i]=hx[i];
                   thy[i]=hy[i];
               }
               for(i=0;i<=4;i++)
               {       x=thx[i];
                   y=thy[i];
                   if(m==0)
                   {       thx[i]=x;
                       thy[i]=c+(c-y);
                   }
                   if(m>0||m<0)
                   {       thx[i]=2*((m*m*y+x)-c*m*m)/((1+m*m)*m)-x;
                       thy[i]=2*(c+m*m*y+x)/(1+m*m)-y;
                   }
                   if(m>=9999)
                   {       thy[i]=y;
                       thx[i]=c+(c-x);
                   }
               }
               drawhouse(thx,thy);

line(getmaxx()/2+lx1,getmaxy()/2-ly1,getmaxx()/2+lx2,getmaxy()/2-ly2);
               break;

               case 4: exit(1);
           }
       }while(ch!=4);
}
