A C++ language program for line drawing using Bresenham's Line Algorithm.
#include<iostream.h>
#include <conio.h>
#include<graphics.h>
void main()
{
int d=DETECT,g;
initgraph(&d,&g,"c://tc//bgi");
clrscr();
int x,y,x1,y1,x2,y2,dx,dy,c1,c2,p,color=1;
cout<<"enter points x1,y1,x2,y2";
cin>>x1>>y1>>x2>>y2;
clrscr();
dx=x2-x1;
dy=y2-y1;
p=2*dy-dx;
c1=2*dy;
c2=2*(dy-dx);
x=x1,y=y1;
putpixel(x,y,color);
while(x<x2)
{ x++;
if(p<0)
{
p=p+c1;
}
else
{
p=p+c2;
y++;
}
putpixel(x,y,color);
}
getch();
closegraph();
getch();
}
Thank you man !
ReplyDelete