Created
January 2, 2013 14:17
-
-
Save 0xKD/4434880 to your computer and use it in GitHub Desktop.
Bresenham's line drawing algorithm ( for m <= 1 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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