/* programe Bresenham's Line- Drawing Algorithm for |m| <1
*/
#include<stdio.h>
#include<graphis.h>
void lineBres(int xa,int ya,int xb,int yb)
{
int dx=abs(xa-xb),dy=abs(ya-yb);
int p=2*dy-dx;
int twoDy=2*dy,twoDyDx=2*(dy-dx);
int x,y,xEnd;
int driver,mode;
driver=DETECT;
mode=0;
initgraph(&driver,&mode,"");
/*Determine which point to use as start,which as end */
if(xa>xb){
x=xb; y=yb;
xEnd=xa;
else {
x=xa;
y=ya;
xEnd=xb;
}
putpixel(x,y,WHITE);
while(x<xEnd){
x++;
if(p<0) p+=twoDy;
else{
y++;
p+=twoDyDx;
}
putpixel(x,y,WHITE); }
getch();
restorecrtmode();
}
void main(){
int x1,y1,x2,y2;
char c;
do{
clrscr();
printf("Enter Coordinate of Start Point of Line at x1,y1 :");
scanf("%d,%d",&yl);
printf("Enter Coordinate of End Point of Line at x2,y2");
scanf("%d,%d",&x2,&y2);
clrscr();
lineBres(x1,y1,x2,y2);
printf("Enter New Line (Y/N):");
c=toupper(getch());
}
while(c!='N');
}