Friday 1 January 2016

Bresenham Line Algorithm Using C++

// C++ Program to implement Bresenham Line Algorithm
#include<iostream>

#include<graphics.h>

using namespace std;

int main()
{
    initwindow(500,600);
    int x0,y0,x1,y1;
    cout<<"Enter the First Line Coordinates";
    cin>>x0>>y0;
    cout<<"Enter the Second Line Coordinates";
    cin>>x1>>y1;

    int dx=x1-x0;
    int dy=y1-y0;
    int d=2*dy-dx;
    int incrE=2*dy;
    int incrNE=2*(dy-dx);
    int x=x0;
    int y=y0;
    putpixel(x,y,5);

    while(x<x1)
    {
        if(d<=0)
        {
            d+=incrE;
            x++;
        }
        else
        {
            d+=incrNE;
            x++;
            y++;
        }
        putpixel(x,y,5);
    }
    delay(50000);
    closegraph();
    return 0;
}

// Output of the above program
Bresenham Line Algorithm
Bresenham Line Algorithm using C++
Bresenham Line Algorithm
Bresenham Line Algorithm using C++
Checkout this video on Bresenham Line Drawing Algorithm Using C++ in CodeBlocks 13.12...




No comments:

Post a Comment