Code archives/Graphics/Fast Line Part deux

This code has been declared by its author to be Public Domain code.

Download source code

Fast Line Part deux by AntonyWells2004
Sort of Inspired to post this by rob farley's one.
This one however is for non-straight lines.

Use rob's one for straight/horizontal lines as it's optimized for that and will be faster, use this for non-straight.

Three ways of color passing. Either pass the 32bit rgb value into red, or pass each red green blue value seperately, or thirdly leave red,green,blue blank(I.e default pars of -1) and it'll use the current 'color' all your other built in drawing funcs do.
function line2(x1#,y1#,x2#,y2#,red=-1,green=-1,blue=-1)
     if red>0 and green=-1
          rgb=red
     else if red=-1
         rgb = colorBlue() or ( colorGreen() shl 8) or ( colorRed() shl 16)
     else 
          rgb=blue or (green shl 8) or (red shl 16)
     endif
     xd#=x2-x1
     yd#=y2-y1
     if abs(xd)>abs(yd) steps=abs(xd) else steps=abs(yd)
     x2=xd/float(steps)
     y2=yd/float(steps)
     for steps=steps to 1 step -1
         writepixelFast x1,y1,rgb
         x1=x1+x2
         y1=y1+y2
     next
end function

Comments

None.

Code Archives Forum