0% found this document useful (0 votes)
64 views

Computer Graphics LAB ECS-554: Rampur Road Moradabad

This program implements polygon clipping using the Cohen-Sutherland algorithm. It defines functions to calculate the boundary codes of polygon points, check if a point is inside the clipping window boundaries, and find the intersection point of an edge with the clipping window boundary. The main function initializes graphics mode, gets user input for polygon points and clipping window coordinates, and calls functions to perform polygon clipping.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Computer Graphics LAB ECS-554: Rampur Road Moradabad

This program implements polygon clipping using the Cohen-Sutherland algorithm. It defines functions to calculate the boundary codes of polygon points, check if a point is inside the clipping window boundaries, and find the intersection point of an edge with the clipping window boundary. The main function initializes graphics mode, gets user input for polygon points and clipping window coordinates, and calls functions to perform polygon clipping.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

RAMPUR ROAD

MORADABAD

Computer Graphics
LAB
ECS-554

Submitted to: Submitted by:


Mr. Neeraj Kumar Verma Name:
(Coordinator) Roll No:
Section: C2
Session 2009-10
Krishna Institute of Management & Technology
Rampur Road, Moradabad

INDEX
S.No. Program Name Remark Date Sign
Quest 1: Write a program in C to implement DDA line algorithm?
// GRAPHICS:-
// SIMPLE DDA PROGRAM:

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

void main()
{
int x1,y1,x2,y2,i,len,gdriver=DETECT,gmode,errorcode;
float incx,incy,x,y;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
clrscr();
printf("enter the value of x1,y1,x2,y2\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
len=abs(x2-x1);
if(abs(y2-y1)>len)
len=abs(y2-y1);
incx=(x2-x1)/len;
incy=(y2-y1)/len;
x=x1+0.5;y=y1+0.5;
for(i=1;i<=len;i++)
{
putpixel(x,y,9);
x=x+incx;
y=y+incy;
}
getch();
}
Quest 2: Write a program in C to implement Bresanham’s Line Drawing
algorithim?
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdio.h>
#include<conio.h>
void main()
{ int gd=DETECT,gm;
int x1,x2,y1,y2;
int i,flag,d;
clrscr();
printf("Enter value of (x1,y1)= ");
scanf("%d%d",&x1,&y1);
printf("Enter value of (x2,y2)= ");
scanf("%d%d",&x2,&y2);
initgraph(&gd,&gm,"c:\\tc\\bgi");
int dx,dy;
dx=abs(x2-x1);
dy=abs(y2-y1);
int x,y,t,s1,s2;
x=x1;
y=y1;
if((x2-x1)>0)
s1=1;
else
s1=-1;
if((y2-y1)>0)
s2=1;
else
s2=-1;
if(dy>dx)
{ t=dx;
dx=dy;
dy=t;
flag=1;
}
else
flag=0;
d=2*dy-dx;
outtextxy(x1,y1,"(x1,y1)");
outtextxy(x2,y2,"(x2,y2)");
i=1;
a:
putpixel(x,y,3);
delay(40);
while(d>=0)
{
if (flag==1)
x=x+s1;
else
y=y+s2;
d=d-2*dx;
}
if (flag==1)
y=y+s2;
else
x=x+s1;
d=d+2*dy;
i++;
if(i<=dx)
goto a;
getch();
closegraph();
}
Quest 3: Write a program in C to implement Brenham’s Circle Drawing
algorithm?
//BRESENHAM'S CIRCLE ALGORITHEM:-

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<complex.h>
#include<math.h>
#include<stdlib.h>

void main()
{
int x1,y1,x,y,r,p,gdriver=DETECT,gmode,errorcode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("graphics error is: %s",grapherrormsg(errorcode));
printf("hit a key to halt");
getch();
exit(1);
}
cleardevice();
printf("enter the value of x1,y1,r");
scanf("%d %d %d",&x1,&y1,&r);
x=0;
y=r;
p=3 - 2 * r;
while(x<=y)
{
putpixel(x1+x,y1+y,2);
putpixel(x1-x,y1+y,2);
putpixel(x1+x,y1-y,2);
putpixel(x1-x,y1-y,2);
putpixel(x1+y,y1+x,2);
putpixel(x1-y,y1+x,2);
putpixel(x1+y,y1-x,2);
putpixel(x1-y,y1-x,2);
if(p<0)
p+=4* x++ +6;
else
p+=4* (x++-y--) +10;
}
getch();
}
Quest 4: Write a program in C to implement Mid-Point Circle Algorithm?
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>

void driver()
{
int gd=DETECT,gmode;
initgraph(&gd,&gmode,"c:\\tc\\bgi");
}

void circlept(int xcentre,int ycentre,int x,int y,int radius)


{
putpixel(xcentre+x,ycentre+y,RED);
putpixel(xcentre-x,ycentre+y,RED);
putpixel(xcentre+x,ycentre-y,RED);
putpixel(xcentre-x,ycentre-y,RED);
putpixel(xcentre+y,ycentre+x,RED);
putpixel(xcentre-y,ycentre+x,RED);
putpixel(xcentre+y,ycentre-x,RED);
putpixel(xcentre-y,ycentre-x,RED);
}
void midptcircle(int xcentre,int ycentre,int radius)
{
int p,x,y;
x=0;
y=radius;
p=1-radius;
circlept(xcentre,ycentre,x,y,radius);
while(x<y)
{
if(p<0)
x++;
else
{
x++;
y--;
}
if(p<0)
p=p+ 2*x +1;
else
p=p+2*(x-y)+1;
circlept(xcentre,ycentre,x,y,radius);
}
}

void main()
{
int xcentre,ycentre,radius;
driver();
getch();
setbkcolor(DARKGRAY);
cleardevice();
printf("\n Enter x co-ordinate of centre::\t");
scanf("%d",&xcentre);
printf("\n Enter y co-ordinate of centre::\t");
scanf("%d",&ycentre);
printf("\n Enter Radius of the circle:: \t");
scanf("%d",&radius);
cleardevice();
midptcircle(xcentre,ycentre,radius);
getch();
closegraph();
}
Quest 5: Write a program in C to implement Line Clipping using Cohen
Sutherland Algorithm?
/*- Line clipping using cohen sutherland algo -*/
/*------------------------------------------------------------*/

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

typedef unsigned int outcode;


enum { TOP=0x1, BOTTOM=0x2, RIGHT=0x4, LEFT=0x8 };
int calcode(float,float,float,float,float,float);
void lineclip(float x0,float y0,float x1,float y1,float xwmin,float
ywmin,float xwmax,float ywmax )
// float x0,y0,x1,y1,xwmin,ywmin,xwmax,ywmax;
{

int gd,gm;
outcode code0,code1,codeout;
int accept = 0, done=0;

code0 = calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);
code1 = calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);

do{
if(!(code0 | code1))
{ accept =1 ; done =1; }
else
if(code0 & code1) done = 1;
else
{
float x,y;
codeout = code0 ? code0 : code1;
if(codeout & TOP)
{
x = x0 + (x1-x0)*(ywmax-y0)/(y1-y0);
y = ywmax;
}
else
if( codeout & BOTTOM)
{
x = x0 + (x1-x0)*(ywmin-y0)/(y1-y0);
y = ywmin;
}
else
if ( codeout & RIGHT)
{
y = y0+(y1-y0)*(xwmax-x0)/(x1-x0);
x = xwmax;
}
else
{
y = y0 + (y1-y0)*(xwmin-x0)/(x1-x0);
x = xwmin;
}
if( codeout == code0)
{
x0 = x; y0 = y;
code0=calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);
}
else
{
x1 = x; y1 = y;
code1 = calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);
}
}
} while( done == 0);

if(accept) line(x0,y0,x1,y1);

rectangle(xwmin,ywmin,xwmax,ywmax);

getch();

}
/*--------------------------------------------------------------------*/

int calcode (float x,float y,float xwmin,float ywmin,float xwmax,float


ywmax)
// float x,y,xwmin,ywmin,xwmax,ywmax;
{
int code =0;

if(y> ywmax)
code |=TOP;
else if( y<ywmin)
code |= BOTTOM;
else if(x > xwmax)
code |= RIGHT;
else if ( x< xwmin)
code |= LEFT;

return(code);
}

/*-------------------------------------------------*/

main()
{

float x2,y2,x1,y1,xwmin,ywmin,xwmax,ywmax;
int gd,gm;

detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");

printf("\n\n\tEnter the co-ordinates of Line :");

printf("\n\n\tX1 Y1 : ");
scanf("%f %f",&x1,&y1);

printf("\n\n\tX2 Y2 : ");
scanf("%f %f",&x2,&y2);

printf("\n\tEnter the co_ordinates of window :\n ");


printf("\n\txwmin , ywmin : ");
scanf("%f %f",&xwmin,&ywmin);
printf("\n\txwmax , ywmax : ");
scanf("%f %f",&xwmax,&ywmax);

line(x1,y1,x2,y2);
rectangle(xwmin,ywmin,xwmax,ywmax);
getch();
cleardevice();

lineclip(x1,y1,x2,y2,xwmin,ywmin,xwmax,ywmax );
getch();
closegraph();

/***************** COHEN-SUTHERLAND LINE CLIPPING ***************/


Quest 6: Write a program in C to implement Polygon Clipping ?
/*Program to implement Ploygon Clipping */
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>

union REGS i,o;


struct pt
{
int x,y;
};

float xl,xr,yt,yb,m,slope[20];
int bc=0,xc,yc,n=0,k,dy,dx,x,y,temp,a[20][2],xi[20];

struct point
{
float x,y;
};

enum bound {left,right,bottom,top};

int inside(struct point p, enum bound b)


{
int c=1;
switch(b)
{
case left : if(p.x<xl)
c=0; break;
case right : if(p.x>xr)
c=0; break;
case bottom : if(p.y>yb)
c=0; break;
case top : if(p.y<yt)
c=0; break;
}
return(c);
}

struct point intersect (struct point p1,struct point p2,enum bound b)


{
struct point t;
float m=0;
if(p2.x!=p1.x) m=(p2.y - p1.y)/(p2.x-p1.x);

switch(b)
{
case left : t.x =xl;
t.y = p2.y+(xl-p2.x)*m;
break;
case right: t.x=xr;
t.y = p2.y + (xr-p2.x)*m;
break;
case bottom: t.y = yb;
if(p1.x==p2.x) t.x=p2.x;
else t.x = p2.x +(yb-p2.y)/m;
break;
case top : t.y = yt;
if(p1.x==p2.x) t.x=p2.x;
else t.x = p2.x +(yt-p2.y)/m;
break;
}
return t;
}
initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}

showmouseptr()
{
i.x.ax=1;
int86(0x33,&i,&o);
return(0);
}

hidemouseptr()
{
i.x.ax=2;
int86(0x33,&i,&o);
return(0);
}

getmousepos(int *button,int *x,int *y)


{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}

void main()
{
enum bound b;
int cou,i,gd=DETECT,gm,flag;struct point p[30],pout[30],z;
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
showmouseptr();
while(bc!=2) //poly
{ getmousepos(&bc,&xc,&yc);
if(bc==1)
{
p[n].x=xc;
p[n].y=yc;
n++;
hidemouseptr();
if(n>1)
line(p[n-2].x,p[n-2].y,xc,yc);
showmouseptr();
delay(200);
}
}
p[n]=p[0];
hidemouseptr();
line(p[n-1].x,p[n-1].y,p[n].x,p[n].y);
showmouseptr();getmousepos(&bc,&xc,&yc);
flag=1;
bc=0;
while(bc!=2) //window
{
if((bc==1) && (flag==1))
{
xl=xc;
yt=yc;
flag=2;
delay(200);
}
else
{
xr=xc;
yb=yc;
delay(200);
}
getmousepos(&bc,&xc,&yc);
}
hidemouseptr();
rectangle(xl,yt,xr,yb);getch();
for(b=left;b<=top;b++)
{
cou =-1;
for(i=0;i<n;i++)
if((inside(p[i],b)==0) && (inside(p[i+1],b)==1))
{
z=intersect(p[i],p[i+1],b);
pout[++cou] =z;
pout[++cou]=p[i+1];
}
else
if((inside(p[i],b)==1)&&(inside(p[i+1],b)==1)) pout[++cou]=p[i+1];
else
if((inside(p[i],b)==1)&&(inside(p[i+1],b)==0))
{
z = intersect(p[i],p[i+1],b);
pout[++cou]=z;
}
pout[++cou]=pout[0];
n=cou;
for(i=0;i<=n;i++) p[i]=pout[i];
}
getch();cleardevice();
rectangle(xl,yt,xr,yb);
for(i=0;i<n;i++) line(p[i].x,p[i].y,p[i+1].x,p[i+1].y);
getch();
for(i=0;i<=n;i++)
{
a[i][0]=p[i].x;
a[i][1]=p[i].y;
}
getch();
}
Quest 7: Write a program in C to draw an Ellipse?
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>

void ellipsemidpoint(int xcenter, int ycenter, int rx, int ry);


void plotpoint(int x,int xcenter, int ycenter,int y);

int maxx, maxy,xcenter,ycenter,rx,ry;

int main(void)
{
int gdriver=DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
maxx = getmaxx();
maxy = getmaxy();
xcenter= 250;
ycenter= 250;
rx= 50;
ry= 50;
ellipsemidpoint(xcenter,ycenter,rx,ry);

getch();
closegraph();

return(0);
}
void ellipsemidpoint( int xcenter, int ycenter,int rx, int ry)
{
int p,px,py,x,y,ry2,rx2,tworx2,twory2;
ry2= ry * ry;
rx2= rx * rx;
twory2= 2 * ry2;
tworx2= 2 * rx2;
x= 0;
y= ry;
plotpoint(x, xcenter, ycenter, y);

p= abs(ry2 - ry2 * ry + ( 0.25 * rx2));


px= 0;
py= tworx2 * y;
while(px<py)
{
x= x+1;
px= px + twory2;
if(p>=0)
{
y= y-1;
py= py - tworx2;
}
if(p<0)
{
p= p + ry2 + px;
}
else
{
p= p + ry2 + px;
}
plotpoint( x, xcenter, ycenter, y);

}
p= abs(ry2 * (x + 6.5) * (x + 6.5) + rx2 * (y - 1) * (y - 1) - rx2 * ry2);
while (y>0)
{
y= y-1;
py= py - tworx2;
if(p<0)
{
x= x +1;
px= px + twory2;
}
if(p>0)
{
p= p + rx2 - py;
}
else
{
p= p + rx2 -py +px;
plotpoint(x, xcenter, ycenter, y);

}
}
}
void plotpoint(int x,int xcenter, int ycenter,int y)
{

putpixel (xcenter + x, ycenter + y, 2);


putpixel (xcenter - x, ycenter + y, 2);
putpixel (xcenter + x, ycenter - y, 2);
putpixel (xcenter - x, ycenter - y, 2);

}
Quest 8:Write a program in C to perform Translation ?
//Translation

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int x1,y1,x2,y2,x,y,x3,y3,x4,y4,ch;
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
do
{
getch();
cleardevice();
printf(" #############MAIN-MENU###############\n");
printf(" TRANSLATION\n");
printf(" 1.LINE\n");
printf(" 2.RECTANGLE\n");
printf(" 3.TRIANGLE\n");
printf("enter your choice:0 for exit:\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("enter the values of line coordinates:");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("enter the translation coordinates:");
scanf("%d%d",&x,&y);
cleardevice();
line(x1,y1,x2,y2);
printf("now hit a key to see translation:");
getch();
line(x1+x,y1+y,x2+x,y2+y);
break;

case 2: printf("enter the top left coordinates:");


scanf("%d%d",&x1,&y1);
printf("enter the bottom right coordinates:");
scanf("%d%d",&x2,&y2);
printf("enter the values of translation coordinates:\n");
scanf("%d%d",&x3,&y3);
cleardevice();
rectangle(x1,y1,x2,y2);
printf("now hit a key to see translation:");
getch();
rectangle(x1+x,y1+y,x2+x,y2+y);
break;
case 3: printf("enter coordinates of line1:\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("enter coordinates for relative line:\n");
scanf("%d%d",&x3,&y3);
printf("enter translation coordinates:\n");
scanf("%d%d",&x,&y);
cleardevice();
line(x1,y1,x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
printf("now hit a key to see translation:");
getch();
moveto(x1+x,y1+y);
lineto(x2+x,y2+y);
moveto(x2+x,y2+y);
lineto(x3+x,y3+y);
moveto(x3+x,y3+y);
lineto(x1+x,y1+y);
break;
case 0: break;
default:printf("invalid choice");break;
}}while(ch!=0);
getch();
closegraph();
}
Quest 9:Write a program in C to perform Rotation?
//rotation

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
float x1,y1,x2,y2,x,y,x3,y3,x4,y4,a;
int ch;
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
clrscr();
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
do
{
printf(" #############MAIN-MENU###############\n");
printf(" ROTATION\n");
printf(" 1.LINE\n");
printf(" 2.RECTANGLE\n");
printf(" 3.TRIANGLE\n");
printf("enter your choice:0 for exit:\n");
scanf("%d",&ch);
switch(ch)

{
case 1: printf("enter the values of line coordinates:");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("enter the value for angle of rotation:");
scanf("%d",&a);
cleardevice();
line(x1,y1,x2,y2);
a=a*(3.14/180);
x1=(x1*cos(a))-(y1*sin(a));
y1=(x1*sin(a))+(y1*cos(a));
x2=(x2*cos(a))-(y2*sin(a));
y2=(x2*sin(a))+(y2*cos(a));
printf("now hit a key to see rotation:");
getch();
line(x1,y1,x2,y2);
break;

case 2: printf("enter the top left coordinates:");


scanf("%d%d",&x1,&y1);
printf("enter the bottom right coordinates:");
scanf("%d%d",&x2,&y2);
printf("enter the value for angle of rotation:");
scanf("%d",&a);
cleardevice();
rectangle(x1,y1,x2,y2);
a=a*(3.14/180);
x1=(x1*cos(a))-(y1*sin(a));
y1=(x1*sin(a))+(y1*cos(a));
x2=(x2*cos(a))-(y2*sin(a));
y2=(x2*sin(a))+(y2*cos(a));
printf("now hit a key to see rotation:");
getch();
rectangle(x1,y1,x2,y2);
break;
case 3: printf("enter coordinates of line1:\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("enter coordinates for relative line:\n");
scanf("%d%d",&x3,&y3);;
printf("enter the angle of rotation:\n");
scanf("%d",&a);
cleardevice();
line(x1,y1,x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
a=a*(3.14/180);
x1=(x1*cos(a))-(y1*sin(a));
y1=(x1*sin(a))+(y1*cos(a));
x2=(x2*cos(a))-(y2*sin(a));
y2=(x2*sin(a))+(y2*cos(a));
x3=(x3*cos(a))-(y3*sin(a));
y3=(x3*sin(a))+(y3*cos(a));
printf("now hit a key to see rotation:");
getch();
moveto(x1,y1);
lineto(x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
break;
case 0: break;
default:printf("invalid choice");break;
}}while(ch!=0);
getch();
closegraph();
}
Quest 10: Write a program in C to perform Shearing?]
//shearing

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int x1,y1,x2,y2,x,y,x3,y3,x4,y4,ch;
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
clrscr();
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
do
{
printf(" #############MAIN-MENU###############\n");
printf(" SHEARING\n");
printf(" 1.LINE\n");
printf(" 2.RECTANGLE\n");
printf(" 3.TRIANGLE\n");
printf("enter your choice:0 for exit:\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("enter the values of line coordinates:");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("enter the value of shearing for xaxis:");
scanf("%d",&x);
printf("enter the value of shearing for y-axis:");
scanf("%d",&y);
cleardevice();
line(x1,y1,x2,y2);
printf("now hit a key to see shear in x_axis:");
getch();
line(x1,y1,x2*x,y2);
printf("\nnow hit a key to see shear in y_axis:");
getch();
line(x1,y1,x2,y2*y);
break;

case 2: printf("enter the top left coordinates:");


scanf("%d%d",&x1,&y1);
printf("enter the bottom right coordinates:");
scanf("%d%d",&x2,&y2);
printf("enter the values of shearing coordinate for
x_shear:\n");
scanf("%d",&x);
printf("enter the values of shearing coordinate for
y_shear:\n");
scanf("%d",&y);

cleardevice();
rectangle(x1,y1,x2,y2);
printf("now hit a key to see shear in x_axis:");
getch();
rectangle(x1,y1,x2*x,y2);
printf("\nnow hit a key to see shear in y_axis:");
getch();
rectangle(x1,y1,x2,y2*y);
break;
case 3: printf("enter coordinates of line1:\n";
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
printf("enter coordinates for relative line:\n");
scanf("%d%d",&x3,&y3);
printf("enter shear coordinate for x_shear:\n");
scanf("%d",&x);
scanf("enter shear coordinate for y_shear:\n");
scanf("%d",&x);

cleardevice();
line(x1,y1,x2,y2);
moveto(x2,y2);
lineto(x3,y3);
moveto(x3,y3);
lineto(x1,y1);
printf("\nnow hit a key to see shear in x_axis:");
getch();
moveto(x1,y1);
lineto(x2*x,y2);
moveto(x2*x,y2);
lineto(x3*x,y3);
moveto(x3*x,y3);
lineto(x1,y1);
printf("\nnow hit a key to see shear in y_axis:");
getch();
moveto(x1,y1);
lineto(x2,y2*y);
moveto(x2,y2*y);
lineto(x3,y3*y);
moveto(x3,y3*y);
lineto(x1,y1);
break;
case 0: break;
default:printf("invalid choice");break;
}}while(ch!=0);
getch();
closegraph();
}

You might also like