Bresenham’s Line Algorithm

Bresenham’s line algorithm is the best known way to render a continuous and straight line through a raster display. I started out allowing floating point operations, but quickly decided to implement the algorithm using only integers. I didn’t like the online explanations and tutorials of the algo, so I decided to write something that I conceptually understood. View my code here.

My algorithm works by increasing an “error” variable by y0 – y1 every iteration. Should the error ever rise above x0-x1, the error is decreased by x0 – x1 and the drawn Y value is increased by 1.