Friday, 27 September 2013

Bresenham's Line Drawing Algo


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
clrscr();
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");

int x1,x2,dx,dy,y1,y2,i=1,p;
cout<<"Enter starting points :";
cin>>x1>>y1;
cout<<"Enter starting points :";
cin>>x2>>y2;

dx=abs(x2-x1);
dy=abs(y2-y1);
p=2*dy-dx;
while(i<=dx)
{
  x1++;
  if (p<0)
   p=p+2*dy;
  else
   {
   p=p+2*dy-2*dx;
   y1++;
   }
   putpixel(x1,y1,WHITE);
   i++;
 }
  getch();

}
Jerrin Andrei Web Developer

No comments:

Post a Comment

Total Pageviews

DjKiRu Initative. Powered by Blogger.