GetLinePoint()
Verfasst: 18.05.2008 10:42
Code: Alles auswählen
Procedure.l ggTAsm(a.l, b.l) ; euclid in asm
!MOV eax, [esp+4] ; copy a to eax
!AND eax, eax ; set flags
!JGE @f ; IF eax >= 0 then jump to @@
!NEG eax ; ELSE negate eax
!@@:
!MOV ebx, [esp+8] ; copy b to ebx
!AND ebx, ebx ; set flags
!JGE @f ; IF ebx >= 0 then jump to @@
!NEG ebx ; ELSE negate ebx
!@@:
!_ggtMyAsmWhile:
!AND ebx, ebx ; set flags
!JLE _ggtMyAsmWend ; jump to end on 0
; c = b
!MOV ecx, ebx ; save b to ecx
; b = a % b
!XOR edx, edx ; extend sign to edx with 0
!IDIV ebx ; div edx:eax / ebx
!MOV ebx, edx ; move rest to b
; a = c
!MOV eax, ecx ; move temp to a
!JMP _ggtMyAsmWhile ; loop
!_ggtMyAsmWend:
ProcedureReturn ; return eax
EndProcedure
Procedure.f GetLinePoint(X1.f, Y1.f, X2.f, Y2.f, X.f)
Protected Xdist.f
Protected Anstieg.f
Protected Y.f
Protected ggT.f
Protected Z.f, N.f
Xdist = X1
X1 - Xdist
X2 - Xdist
X - Xdist
Z = (Y2-Y1)
N = (X2-X1)
ggT = ggTAsm(Z, N)
Z = Z/ggT
N = N/ggT
Anstieg = Z/N
Y = (Anstieg*X)+Y1
ProcedureReturn Y
EndProcedure
Macro Paint
StartDrawing(WindowOutput(0))
DrawImage(ImageID(0), 0, 0)
StopDrawing()
EndMacro
Macro Draw
CreateImage(0, 800, 600)
StartDrawing(ImageOutput(0))
Box(0, 0, 800, 600, $eeeeee)
start = ElapsedMilliseconds()
MX = WindowMouseX(0)
MY = WindowMouseY(0)
If MX = -1
MX = 800
EndIf
If MY = -1
MY = 600
EndIf
For x = 0 To MX Step 10
y = GetLinePoint(0, 0, MX, MY, x)
RandomSeed(x)
Box(x, y, 5, 5, RGB(0, 0, Random(255)))
Next
Time = ElapsedMilliseconds()-start
DrawText(5, 5, Str(Time)+" ms", 0, $FFFFFF)
StopDrawing()
Paint
EndMacro
OpenWindow(0, 0, 0, 800, 600, "LinePoint", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
Draw
Repeat
Event = WaitWindowEvent(1000)
If Event = #PB_Event_Repaint
Paint
ElseIf Event = 512
Draw
ElseIf Event = #PB_Event_CloseWindow
Break
ElseIf Event = 0
Draw
EndIf
ForEver
Feedback erwünscht.
mfg coder