Restored from previous forum. Originally posted by MrVainSCL.
[== How does a Line() command works: ==]
---------------------------------------
Maybe some of you have asked yourself how does a Line() command work to get such a smooth drawed line. Some time ago i coded a small Line() replace to see how does it works... Here is the basical behind it. Note: You can´t test it, because PB2.80 dont support the Sgn() math command at the moment ;( But hey, it works!
Code: Select all
;--------------------------------------------
;
; PureBasic - How does a Line() command work
;
;--------------------------------------------
;
Procedure.l Sgn(x.l)
If x>>31 = 1
ProcedureReturn -1
Else
ProcedureReturn 1
EndIf
EndProcedure
Procedure MyLine(x1,y1,x2,y2)
;
x = x1
y = y1
StartDrawing(ScreenOutput()) ; ### START DRAWING ###
Plot (x,y) ; Hopefully faster DXPlot() for DirectX support soon :wink:
StopDrawing() ; ### STOP DRAWING ###
f = 0
;
Repeat
f1 = f + Abs(x2 - x1)
f2 = f - Abs(y2 - y1)
;
;------------------------
;
If Abs(f1) >= Abs(f2)
f = f2
x = x + Sgn(x2 - x1) ; Still miss Sgn() math command as standard function in PureBasic!
Else
f = f1
y = y + Sgn(y2 - y1)
EndIf
;
;------------------------
;
Plot (x,y)
Until x = x2 And y = y2
;
EndProcedure
;
;--------------------------------------------
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...
greetz
MrVainSCL! aka Thorsten