Skip to content

Instantly share code, notes, and snippets.

@fjenett
Created March 31, 2010 07:00
Show Gist options
  • Save fjenett/350027 to your computer and use it in GitHub Desktop.
Save fjenett/350027 to your computer and use it in GitHub Desktop.
Naive bresenham
// simple line algorithm to draw / read along a line.
//
// assumes x1 < x2 and y1 < y2
int x1=10,x2=100;
int y1=20,y2=40;
// assumes xdiff > ydiff
float xdiff = x2-x1;
float ydiff = y2-y1;
float ystep = ydiff / xdiff;
for ( int i = 0; i < xdiff; i++ )
{
float x = i + x1;
float y = y1 + i * ystep;
point( x, y );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment