#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
struct vertex
{
int x;
int y;
}v1,v2,v3,v4;
float count;
void plot(vertex a,vertex b,vertex c, vertex d,int p)
{ if(p==0)
{
setcolor(5);
}
else{
setcolor(6);
}
/* draw a diagonal line */
line(a.x+150, a.y+150, b.x+150, b.y+150);
line(b.x+150, b.y+150, c.x+150, c.y+150);
line(c.x+150, c.y+150, d.x+150, d.y+150);
line(d.x+150, d.y+150, a.x+150 ,a.y+150);
/* clean up */
cout<<“/n”;
}
void scale(int p,float &count)
{
int flag=0;
float cdec;
vertex v,w,a1,a2;
int inc,dec;
v=v2;
w=v3;
//cout<<“flag”<<flag;
if(p==1)
{
count=count+0.05;
cout<<“count is”<<count;
v2.x=v3.x=v.x;
//cout<<“w.y is”<<w.y<<” count is”<<count<<“v1.y is”<<v1.y;
v3.y=w.y*count+(1-count)*v1.y;
//cout<<“y coordinate of third vertex is”<<v3.y;
inc=v3.y-w.y;
v2.y=v.y-inc;
//cout<<“y coordinate of 2nd vertex is”<<v2.y;
//cout<<“\n inc is”<<inc;
//cout<<“a1 “<<a1.x<<” “<<a1.y<<” a2″<<a2.x<<” “<<a2.y;
//cout<<“v “<<v2.x<<” “<<v2.y<<“w”<<v3.x<<” “<<v3.y;
}
if(p==0)
{v=v2;
w=v3;
cdec=1/count;
//cout<<” “<<cdec;
v2.x=v3.x=v.x;
v3.y=w.y*cdec+(1-cdec)*v1.y;
//cout<<” a1 calculated “<<a1.y;
dec=w.y-v3.y;
//cout<<“dec is”<<dec;
v2.y=v.y+dec;
count=count-0.05;
//cout<<“” <<a1.x <<“\t”<<a1.y<<” “<<a2.x<<” “<<a2.x<<” “<<a2.y;
//cout<<“\n values of v and w”;
//cout<<v.x<<” “<<v.y<<” “<<w.x<<” “<<w.y;
}
plot(v1,v2,v3,v4,p);
}
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xmax, ymax;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, “”);
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf(“Graphics error: %s\n”, grapherrormsg(errorcode));
printf(“Press any key to halt:”);
getch();
exit(1);
}
cout<<“enter 1 vertex x coordinate”;
cin>>v1.x;
cout<<“enter y”;
cin>>v1.y;
v2.x=v1.x+100;
v2.y=v1.y;
v3.x=v1.x+100;
v3.y=v1.y+100;
v4.x=v1.x;
v4.y=v1.y+100;
/* draw a diagonal line */
line(v1.x, v1.y, v2.x, v2.y);
line(v2.x, v2.y, v3.x, v3.y);
line(v3.x, v3.y, v4.x, v4.y);
line(v4.x, v4.y, v1.x,v1.y);
/* clean up */
char choice;
int flag2=0;
count=1.0;
do
{
if(flag2==0)
{
cout<<“enter w for increase”;
cout<<“\n enter s for decrease”;
cout<<“\n enter e for exit”;
}
flag2++;
choice=getch();
switch(choice)
{
case ‘w’: scale(1,count);
break;
case ‘s’: scale(0,count);
break;
}
}
while(choice!=’e’);
getch();
closegraph();
return 0;
}