Task

Using the data storage type defined on the Bitmap page for raster graphics images,

draw a line given two points with Bresenham's line algorithm.




(lx0, ly0, lx1, ly1)
Prgm
  Local steep, x, y, dx, dy, ystep, error, tmp
  abs(ly1 - ly0) > abs(lx1 - lx0) → steep
  If steep Then
    lx0 → tmp
    ly0 → lx0
    tmp → ly0
    lx1 → tmp
    ly1 → lx1
    tmp → ly1
  EndIf
  If lx0 > lx1 Then
    lx0 → tmp
    lx1 → lx0
    tmp → lx1
    ly0 → tmp
    ly1 → ly0
    tmp → ly1
  EndIf
  lx1 - lx0 → dx
  abs(ly1 - ly0) → dy
  when(ly0 < ly1, 1, –1) → ystep
  intDiv(dx, 2) → error
  ly0 → y
  For x,lx0,lx1
    If steep Then: PxlChg x, y :Else: PxlChg y, x :EndIf
    error - dy → error
    If error < 0 Then
      y + ystep → y
      error + dx → error
    EndIf
  EndFor
EndPrgm