CG Thin
CG Thin
ROLL.NO: SEB239
Descrip on: Program to draw a Thin Line using Bresenham's Line Drawing Algorithm
#include<stdio.h>
#include <graphics.h>
#include <stdlib.h>
main(void)
i,x,y,x1,y1,x2,y2,dx,dy,length,P0;
scanf("%d%d",&x1,&y1);
scanf("%d%d",&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>dy)
length=dx;
else
length=dy;
putpixel(x1,y1,2);
x=x1;
y=y1;
P0=2*dy-dx;
for(i=1;i<=length;i++)
if(P0<0)
x=x+1;
y=y+0;
putpixel(x,y,2);
P0=P0+2*dy;
else
x=x+1;
y=y+1;
putpixel(x,y,2);
P0=P0+2*dy-2*dx;
/* clean up */
getch();
closegraph();
return 0;