Code archives/Graphics/Snarty Line (ProPixel Code)

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

Download source code

Snarty Line (ProPixel Code) by Snarty2002
I took a look at the Bresham line algo and found it better to write a native Blitz algo for line Drawing. Includes a mode switch for XOR pixel drawing. Is aimed at drawing lines with Brushes/Sprites/Images etc, but is super fast with Pixels.

NOTE: Change the Draw image part to WritePixelFast to gain maximum speed on line creation.
; Snarty Line
; Written By Paul Snart (Snarty)
; Oct 2001

; Stx,Sty = Start pixel posistion
; Enx,Eny = End point.
; Mode    = False = Normal, True = XOR'ed
; CurBrush= Image Memory Handle

Function SLine(stx#,sty#,enx#,eny#,mode)

	mvx#=Stx-enx:mvy#=sty-eny
	If mvx<0 mvx=-mvx
	If mvy<0 mvy=-mvy
	If mvy>mvx mv#=mvy Else mv#=mvx
	stpx#=(mvx/mv):If Stx>enx stpx=-stpx
	stpy#=(mvy/mv):If Sty>eny stpy=-stpy
	If Mode=1 LockBuffer BackBuffer()
	For nc=0 To Floor(mv)
		If mode=0
			If BrushMode<>1 Or Brush=0
				DrawImage CurBrush,stx,sty
			Else
				If BrushMode=1
					DrawBlock CurBrush,stx,sty
				EndIf
			EndIf
		Else
			rgb=ReadPixelFast(stx,sty) And $FFFFFF
			ColD=$FFFFFF Xor rgb
			WritePixelFast stx,sty,ColD
		EndIf
		stx=stx+stpx:sty=sty+stpy
	Next
	If Mode=1 UnlockBuffer BackBuffer()

End Function

Comments

None.

Code Archives Forum