Skip to content

Instantly share code, notes, and snippets.

@0xKD
Created January 2, 2013 14:17
Show Gist options
  • Save 0xKD/4434880 to your computer and use it in GitHub Desktop.
Save 0xKD/4434880 to your computer and use it in GitHub Desktop.
Bresenham's line drawing algorithm ( for m <= 1 )
// Bresenham's line drawing algorithm ( for m <= 1 )
#include <iostream>
using namespace std;
int drawBH(int x1,int y1,int x2,int y2)
{
int x = x1, y = y1;
int dx = x2-x1;
int dy = y2-y1;
int e = 2*dy - dx;
for(x; x <= x2; x++)
{
cout <<"x = "<<x<<", y = "<<y<<"\n";
if (e < 0)
{
e += 2*dy;
}
else
{
y += 1;
e += 2*dy - 2*dx;
}
}
return 0;
}
int main()
{
drawBH(0,0,6,2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment