Develop the program for Bresenham’s Line drawing algorithm in C++ - BSC IT PRACTICALS

Monday, January 15, 2018

Develop the program for Bresenham’s Line drawing algorithm in C++


CODE:

#include<graphics.h>
#include<iostream.h>
#include<math.h>
#include<conio.h>

void main( )
{
    float x,y,x1,y1,x2,y2,dx,dy,e;
    int i,gd,gm;
    gd=DETECT;
    initgraph(&gd,&gm,"c:\\turboc3\\bgi");

    cout<<"Enter the value of x1 and y1 : ";
    cin>>x1>>y1;
    cout<<"Enter the value of x2 and y2: ";
    cin>>x2>>y2;

    dx=abs(x2-x1);
    dy=abs(y2-y1);
    x=x1;y=y1;
e=(dy/dx)-0.5;
putpixel(x,y,15);
for(i=1;i<=dx;i++){
while(e>=0){
y=y+1;
e=e-1;

}
x=x+1;
e=dy/dx+e;
putpixel(x,y,15);

}
getch();
closegraph();

}

No comments:

Post a Comment