Code archives/Graphics/Fast Line
This code has been declared by its author to be Public Domain code.
Download source code
| I know this doesnt sound that exciting, however, if you want to draw only vertical and horizonal lines it's a darn sight faster than the standard line function.|
I could have locked and unlocked the backbuffer() in the function however, it's much faster to lockbuffer, draw a bunch of lines, then unlockbuffer.
Simple as that... If you try to draw a line that isn't horizontal or vertical it won't do anything.
Example code at the top, all you actually need is the function.
; Fast line, 2004 Rob Farley ; firstname.lastname@example.org ;========================================================== ; example code ;========================================================== Graphics 640,480 SetBuffer BackBuffer() LockBuffer BackBuffer() For x=0 To 200 Step 20 For y=0 To 200 Step 20 fline(0,y,200,y,255,128,0) fline(x,0,x,200,255,0,0) Next Next UnlockBuffer BackBuffer() Flip WaitKey ;========================================================== ; end of example code ;========================================================== Function fLine(x,y,x1,y1,r=255,g=255,b=255) ; fLine will only draw horizonal or vertical lines, no diagonals ; Defaults to a white line. argb=(b Or (g Shl 8) Or (r Shl 16) Or ($ff000000)) If x=x1 If y>y1 Then t=y1:y1=y:y=t For n=y To y1 WritePixelFast x,n,argb,BackBuffer() Next EndIf If y=y1 If x>x1 Then t=x1:x1=x:x=t For n=x To x1 WritePixelFast n,y,argb,BackBuffer() Next EndIf End Function
| Is this even faster than Rect for drawing horz/vert lines, then? |
| Yes. |
Code Archives Forum