Hallo ihr lieben,
ich bin seit einiger Zeit schon auf https://autoit.de/www.Rosettacode.org unterwegs und versuche einige Tasks zu lösen.
Derzeit hänge ich an dem Brownian Tree
Hier mein Derzeitiger Code:
Spoiler anzeigen
Brownian_Tree(400)
[/autoit] [autoit][/autoit] [autoit]Func Brownian_Tree($particles)
Local $sizex = 200, $sizey = 200
Local $xstart, $ystart, $x, $y
Local $Bt_array[$sizex][$sizey]
$hGui = GUICreate("Brownian Tree", $sizex, $sizey)
GUISetState()
$Bt_array[Round((UBound($Bt_array) - 1) / 2, 0)][Round((UBound($Bt_array, 2) - 1) / 2, 0)] = "X"
GUICtrlCreateLabel("", Round((UBound($Bt_array) - 1) / 2, 0), Round((UBound($Bt_array, 2) - 1) / 2, 0), 1, 1)
GUICtrlSetBkColor(-1, 0x000000)
$counter = 0
While $counter <> $particles
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $counter = ' & $counter & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$x = Random(0, $sizex - 1, 1)
$y = Random(0, $sizey - 1, 1)
If $Bt_array[$x][$y] = "X" Then ContinueLoop
If $x + 1 <= $sizex - 1 Then
If $Bt_array[$x + 1][$y] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ContinueLoop
EndIf
EndIf
If $x - 1 >= 0 Then
If $Bt_array[$x - 1][$y] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ContinueLoop
EndIf
EndIf
If $y + 1 <= $sizey - 1 Then
If $Bt_array[$x][$y + 1] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ContinueLoop
EndIf
EndIf
If $y - 1 >= 0 Then
If $Bt_array[$x][$y - 1] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ContinueLoop
EndIf
EndIf
While True
$rnd = String(Random(1, 4, 1))
Switch $rnd
Case "1"
If $x + 1 > $sizex - 1 Then ContinueLoop
$x += 1
Case "2"
If $x - 1 < 0 Then ContinueLoop
$x -= 1
Case "3"
If $y + 1 > $sizey - 1 Then ContinueLoop
$y += 1
Case "4"
If $y - 1 < 0 Then ContinueLoop
$y -= 1
EndSwitch
If $x + 1 <= $sizex - 1 Then
If $Bt_array[$x + 1][$y] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ExitLoop
EndIf
EndIf
If $x - 1 >= 0 Then
If $Bt_array[$x - 1][$y] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ExitLoop
EndIf
EndIf
If $y + 1 <= $sizey - 1 Then
If $Bt_array[$x][$y + 1] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ExitLoop
EndIf
EndIf
If $y - 1 >= 0 Then
If $Bt_array[$x][$y - 1] = "X" Then
$Bt_array[$x][$y] = "X"
$counter += 1
GUICtrlCreateLabel("", $x, $y, 1, 1)
GUICtrlSetBkColor(-1, 0xFF0000)
ExitLoop
EndIf
EndIf
WEnd
WEnd
Return $Bt_array
EndFunc ;==>Brownian_Tree
Er funktioniert, allerdings dauert es sehr lange bis eine große Anzahl an Partikeln erstellt wurde (~3Minuten für ~200 Partikel),
ich denke aber, das es noch einige Möglichkeiten zur Optimierung gibt, vielleicht weiß ja jemand, wie man es noch schneller machen kann.
Als Ausgabe bzw. Anzeige würde ich gerne das GUI beibehalten, sodass man den Baum wachsen sieht,
für Vorschläge bin ich dankbar