diff --git a/Bresenham's Line Drawing Algorithm b/Bresenham's Line Drawing Algorithm new file mode 100644 index 0000000..6112b89 --- /dev/null +++ b/Bresenham's Line Drawing Algorithm @@ -0,0 +1,69 @@ +#include +#include +#include + +main(){ + int x1,x2,i,y1,y2,x,y,dx,dy,ds=0,dt=0,d,gd=DETECT,gm,xinc=0,yinc=0; + printf("\nEnter the coordinates of line\nx1: "); + scanf("%d",&x1); + printf("y1: "); + scanf("%d",&y1); + printf("x2: "); + scanf("%d",&x2); + printf("y2: "); + scanf("%d",&y2); + initgraph(&gd, &gm, ""); + setcolor(BLUE); + setfillstyle(SOLID_FILL, WHITE); + rectangle(0,0, getmaxx(),getmaxy()); + floodfill(5,5,BLUE); + dx=x2-x1, dy=y2-y1,x=x1,y=y1; + if (dx<0) + dx=-dx; + xinc = 1; + if(dy<0) + dy=-dy; + yinc=1; + if(x2dy){ + d=(2*dy)-dx; + ds += 2*dy; + dt += (2*dy)-(2*dx); + i=0; + while (i