# Bresenham's line algorithm

The **Bresenham line algorithm** is an algorithm which determines which order to form a close approximation to a straight line between two given points. It is commonly used to draw lines on a computer screen, as it uses only integer addition, subtraction and bit shifting, all of which are very cheap operations in standard computer architectures.

## Algorithm: edit

In the following pseudocode sample `plot(x,y)`

plots a point and `abs`

returns absolute value:

functionline(x0, x1, y0, y1)intdeltax := x1 - x0intdeltay := y1 - y0realerror := 0realdeltaerr := abs (deltay / deltax) // Assume deltax != 0 (line is not vertical), // note that this division needs to be done in a way that preserves the fractional partinty := y0forxfromx0tox1 plot(x,y) error := error + deltaerriferror ≥ 0.5theny := y + 1 error := error - 1.0