Sub BresenhamLine(x0, y0, x1, y1)
steep = False
If Abs(y1 - y0) > Abs(x1 - x0) Then
steep = True
'swap(x0, y0)
x = x0 : x0 = y0 : y0 = x
'swap(x1, y1)
x = x1 : x1 = y1 : y1 = x
End If
If x0 > x1 Then
'swap(x0, x1)
x = x0 : x0 = x1 : x1 = x
'swap(y0, y1)
x =y0 : y0 = y1 : y1 = x
End If
deltax = Int(x1 - x0)
deltay = Int(Abs(y1 - y0))
error = Int(deltax / 2)
y = y0
If y0 < y1 Then
ystep = 1
Else
ystep = -1
End If
For x = x0 To x1
If steep Then plot(y,x) Else plot(x,y)
error = error - deltay
If error < 0 Then
y = y + ystep
error = error + deltax
End If
Next
End Sub