Bresenham algorithm
In your implementation you need to handle all slopes!
First, reorder endpoints so that x1, <= x2
y2,-y1 >= 0, x2,-x1 >= y2,-y1 positive slope <= 1
y2,-y1 >= 0, x2,-x1 < y2,-y1 positive slope > 1
y2,-y1 < 0, x2,-x1 >= y1,-y2 negative slope >= -1
y2,-y1 < 0, x2,-x1 < y1,-y2 negative slope < -1
In each case, make appropriate substitutions in