Sunday 11 November 2012

Bresenhams Algorithm (Line Drawing )

#include<graphics.h>
void main ()
{
int x,y,x0,y0,x1,y1,m,n,p;
int gd=DETECT,gm;
initgraph (&gd,&gm,"c:\\tc\\bgi");
printf ("\n Enter the co-ordinate of starting point");
scanf ("%d%d",&x0,&y0);
printf ("\n Enter the co-ordinate of end point");
scanf ("%d%d",&x1,&y1);
x=x0;
y=y0;
m=(x1-x0);
n=(y1-y0);
p=2*n-m;
while (x!=x1)
{
if (p<0)
{
x=x+1;
p=p+2*n;
putpixel (x,y,5);
}
else
{
x++;
y++;
p=p+2*(n-m);
putpixel (x,y,5);
}
}
getch();
closegraph();
}

No comments:

Post a Comment