Bresenham's line algorithm

BlitzMax Forums/BlitzMax Programming/Bresenham's line algorithm

I think the floating point version is simpler, not sure if it's as fast or not.

Please note I just typed this into the message, this is entirely untested, but it's something along these lines.

'Floating point line-draw in BlitzMax
Strict
Graphics 640,480,0

Local x1,y1,x2,y2,xdiff,ydiff,xstep,ystep:Float
Local pixels,x,y:Int
Repeat
   x1=320
   y1=240
   x2=MouseX()
   y2=MouseY()
   xdiff=x2-x1
   ydiff=y2-y1
   If xdiff>ydiff
      If xdiff>0 Then xstep=1 else xstep=-1
      ystep=Abs(ydiff)/Abs(xdiff)
      if ydiff<0 then ystep=-ystep
      pixels=Abs(xdiff)
   Else
      If ydiff>0 Then ystep=1 else ystep=-1
      xstep=Abs(xdiff)/Abs(ydiff)
      if xdiff<0 then xstep=-xstep
      pixels=Abs(ydiff)
   EndIf
   For local counter:Int=0 to pixels-1
      Plot x1,y1
      x1:+xstep
      y1:+ystep
   Next
Until KeyHit(KEY_ESCAPE)