#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm,ch,k,w,j,q;
int x1,x2,y1,y2;
float xiner,yiner,x,y;
float dx,dy,steps,i,l;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("ENTER THE VALUE OF xA,XB,YA,YB \n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xiner=dx/steps;
yiner=dy/steps;
do
{
x=x1;
y=y1;
putpixel(x,y,6);
printf("\nenter the choice for line type");
printf("\n 1. solid line");
printf("\n 2. dash line");
printf("\n 3. dot line");
printf("\n 4.dashdot line");
printf("\n5.thick line");
scanf("%d",&ch);
cleardevice();
switch(ch)
{
case 1: //solid
for(k=1;k<=steps;k++)
{
putpixel(x,y,4);
x=x+xiner;
y=y+yiner;
outtextxy(x2,y2,"(xb,yb)");
outtextxy(x1,y1,"(xa,ya)");
}
break;
case 2: //dashed
for(k=1;k<=steps;k++)
{
if( (k%5!=0) )
putpixel(x,y,3);
x=x+xiner;
y=y+yiner;
outtextxy(x2,y2,"(xb,yb)");
outtextxy(x1,y1,"(xa,ya)");
}
break;
case 3: //dot
for(k=1;k<=steps;k++)
{
if( (k%2!=0) )
putpixel(x,y,3);
x=x+xiner;
y=y+yiner;
outtextxy(x2,y2,"(xb,yb)");
outtextxy(x1,y1,"(xa,ya)");
}
break;
case 4:
//dashdot
for(k=1;k<=steps;k++)
{
if(k%8!=0)
{
putpixel(x,y,3);
}
else
{
x=x+xiner;
y=y+yiner;
k++;
putpixel(x,y,4);
x=x+xiner;
y=y+yiner;
k++;
}
x=x+xiner;
y=y+yiner;
outtextxy(x2,y2,"(xb,yb)");
outtextxy(x1,y1,"(xa,ya)");
}
break;
case 5: //thick
printf("\n enter width:");
scanf("%d",&w);
for(k=1;k<=steps;k++)
{
if(x1==x2)
{ for(j=1;j<=w;j++)
{
putpixel(x+j,y,1);
}
}
else if(y1==y2)
{
for(j=1;j<=w;j++)
{
putpixel(x,y+j,1);
}
}
else
{
for(j=1;j<=w;j++)
{
putpixel(x+j,y-j,1);
}
}
x=x+xiner;
y=y+yiner;
outtextxy(x1,y1,"(xb,yb)");
outtextxy(x2,y2,"(xa,ya)");
}
break;
}
printf("\nDO U WANT TO CONTINUE?(1/0)");
scanf("\n%d",&q);
}while(q!=0);
getch();
}