CODE:/*Bresenham's Line Algorithm*/ #include<stdio.h> #include #include<math.h> #include
void main() { int gd=DETECT,gm,i; float steps,dx,dy,x,y,x1=200,y1=200,x2=400,y2=400,e; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); printf("Enter 1st point:"); scanf("%d%d",&x1,&y1); printf("Enter 2nd point:"); scanf("%d%d",&x2,&y2); dx = x2-x1; dy = y2-y1; if(dx>dy) steps = abs(dx); else steps = abs(dy); x = x1; y = y1; e = 2*dy - dx; for(i=0;i<steps;i++) { putpixel(x,y,GREEN); while(e>=0)
{ y = y + 1; e = e - 2*dx; } x = x + 1; e = e + 2*dy; }
getch(); closegraph(); }