Bresenham algorithm
Assume the slope to be between 0 and 1.
int y = y1; int dy = y2-y1;
int dxdy = y2-y1+x1-x2;
int F = y2-y1+x1-x2; int x;
for( x = x1; x < =x2; x++ ) {
drawpixel(x,y);
if( F < 0 ) {
F += dy;
} else {
y++; F += dxdy;
}
}
Previous slide
Next slide
Back to first slide
View graphic version