BRESENHAM LINE DRAWING


 /* BRESENHAM LINE DRAWING */
#include<stdlib.h>
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<math.h>
#include<dos.h>

void   main()
{clrscr();
float i,e,x,y,x1,y1,x2,y2,dx,dy,length;

printf("enter the value of x1:\t");
scanf("%f",&x1);
 printf("enter the value of y1:\t");
scanf("%f",&y1);
printf("enter the value of x2:\t");
scanf("%f",&x2);
printf("enter the value of y2:\t");
scanf("%f",&y2);
int gdrives=DETECT,gmode;
initgraph(&gdrives,&gmode,"f:\\tc\\bin\\bgi");
dx=abs(x2-x1);
dy=abs(y2-y1);
x=x1;
y=y1;
e=2*dy-dx;
i=1;
do
{
putpixel(x,y,15);
while(e>=0)
{
y=y+1;
e=e-2*dx;
}
delay(100);
x=x+1;
e=e+2*dy;
i=i+1;
}
while(i<=dx);
getch();
closegraph();
}

Comments