Ich wollte mal ausprobieren, ob es eine schnellere Methode Linien zu zeichnen gibt.
Meine suche danach war leider erfolglos.
Aber das Ergebniss ist trotzdem ganz interresant:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN]
Graphics 640,480,32,2
Dim e(3)
Cls Text 100,10,\"Parametrisierte Geradengleichung\"
timer1 = MilliSecs()
For t = 1 To 50 For i = 1 To 640 Step 50 line2 0,0,i,480 Next For i = 640 To 1 Step -50 line2 640,0,i,480 Next Next
e(0) = MilliSecs() - timer1 Text 100,25,\"1200 Linien: \" + e(0) + \" ms\" WaitKey()
Cls Text 100,10,\"Bresenham-Algorithmus\"
timer1 = MilliSecs()
For t = 1 To 50 For i = 1 To 640 Step 50 line3 0,0,i,480 Next For i = 640 To 1 Step -50 line3 640,0,i,480 Next Next
e(1) = MilliSecs() - timer1 Text 100,25,\"1200 Linien: \" + e(1) + \" ms\" WaitKey()
Cls Text 100,10,\"Geradengleichung als Funktion\"
timer1 = MilliSecs()
For t = 1 To 50 For i = 1 To 640 Step 50 line4 0,0,i,480 Next For i = 640 To 1 Step -50 line4 640,0,i,480 Next Next
e(2) = MilliSecs() - timer1 Text 100,25,\"1200 Linien: \" + e(2) + \" ms\" WaitKey()
Cls Text 100,10,\"BlitzBasic Line-Funktion\"
timer1 = MilliSecs()
For t = 1 To 50 For i = 1 To 640 Step 50 Line 0,0,i,480 Next For i = 640 To 1 Step -50 Line 640,0,i,480 Next Next
e(3) = MilliSecs() - timer1 Text 100,25,\"1200 Linien: \" + e(3) + \" ms\" WaitKey()
Cls Text 100,25,\"Zusammenfassung:\" Text 100,50,\"BlitzBasic Line-Funktion: \" + e(3) + \"ms\" Text 100,65,\"Geradengleichung als Funktion: \" + e(2) + \"ms\" Text 100,80,\"Bresenham-Algorithmus: \" + e(1) + \"ms\" Text 100,95,\"Parametrisierte Geradengleichung: \" + e(0) + \"ms\"
WaitKey() : End
Function line2(x, y, dx#, dy#) LockBuffer Local r#, step1#
px = x py = y dy# = dy - y dx# = dx - x
step1# = 1.0 / Sqr(dx#*dx# + dy#*dy#) r# = 0.0 While r < 1 r=r+step1 x = Int(x1 + r*dx +0.5) y = Int(y1 + r*dy +0.5) WritePixelFast(x+px,y+py,-1664454) Wend UnlockBuffer End Function
Function line3(x1,y1,x2,y2) LockBuffer Local error, delta, schritt, inc_x, inc_y
x = x1 y = y1
dy = y2 - y1 dx = x2 - x1
If dx > 0 inc_x = 1 Else inc_x = -1 EndIf If dy > 0 inc_y = 1 Else inc_y = -1 EndIf If(Abs(dy) < Abs(dx)) Then error = Abs(dx) * (-1) delta = 2*Abs(dy) schritt = 2*error While x <> x2 WritePixelFast(x,y,-1664454) x = x + inc_x error = error + delta If error > 0 y = y + inc_y error = error + schritt EndIf Wend Else error = Abs(dy)* (-1) delta = 2*Abs(dx) schritt = 2*error While y <> y2 WritePixelFast(x,y,-1664454) y = y + inc_y error = error + delta If error > 0 Then x = x + inc_x error = error + schritt EndIf Wend EndIf WritePixelFast(x2,y2,-1664454) UnlockBuffer End Function
Function line4(x1,y1,x2,y2) LockBuffer Local x, y Local s#, c#
s = Float(y2 - y1) / Float(x2 - x1) c = Float(y1*x2 - y2*x1) / Float(x2 - x1)
x = x1 y = y1
If x < x2 Then While x <= x2 y = Int(s*x + c + 0.5) WritePixelFast(x,y,-1664454) x = x + 1 Wend Else While x >= x2 y = Int(s*x + c + 0.5) WritePixelFast(x,y,-1664454) x = x - 1 Wend EndIf UnlockBuffer End Function
|