#include
#include
#include
#define gx getmaxx()
#define gy getmaxy()
void main()
{
int gd=DETECT,gm,i,x,y,x1,y1,x2,y2,xinc,yinc,dx,dy,p;
printf("Enter the endpoints of line:\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
initgraph(&gd,&gm,"c:\\tc\\bgi ");
x=x1;
y=y1;
putpixel(x,y,14);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(x1
xinc=1;
else
xinc=-1;
if(y1
yinc=1;
else
yinc=-1;
if(dx>=dy)
{
p+=2*dy-dx;
while(x!=x2)
{
x+=xinc;
if(p<0)
p+=2*dy;
else
{
p+=2*(dy-dx);
y+=yinc;
}
putpixel(x,y,14);
}
}
else
{
p+=2*dx-dy;
while(y!=y2)
{
y+=yinc;
if(p<0)
p+=2*dx;
else
{
p+=2*(dx-dy);
x+=xinc;
}
putpixel(x,y,14);
}
}
/*closegraph();*/
getch();
}
0 comments:
Post a Comment