Brownian Tree

  • 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
    [autoit]

    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

    [/autoit]

    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 :)

  • Vorab: Ziemlich cool :thumbup: .
    Allerdings bin ich mir nicht sicher ob das wirklich das selbe Prinzip ist, wie es auf Rosettacode beschrieben wird... Entweder habe ich es falsch verstanden, oder du :D.

    Das wäre meine Interpretation. Viel schneller lässt sich dieser Algorithmus mit AutoIt nicht umsetzen (es sei denn man schummelt). Aber am Algorithmus den ich verwende lässt sich sicherlich noch feilen ^^.

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ; -Author: name22 (http://www.autoit.de)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hDll_GDI32 = DllOpen("gdi32.dll")
    Global $iX_Pos, $iY_Pos, $iX_Dir, $iY_Dir

    [/autoit] [autoit][/autoit] [autoit]

    Global $sFile = FileSaveDialog("Save Picture", "", "Bitmap (*.bmp)")
    If @error Then Exit

    [/autoit] [autoit][/autoit] [autoit]

    Global $iCount = 10000
    Global $iSize = 200

    [/autoit] [autoit][/autoit] [autoit]

    Global $iColorBGR_Seed = 0x0000FF
    Global $iColorBGR_Not = 0x000000
    Global $iColorBGR_Set = 0xFF0000
    Global $iColorBGR_Mov = 0x202020

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Brownian Tree", $iSize, $iSize)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $hDC_Window = _WinAPI_GetDC($hWnd)
    $hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iSize, $iSize)
    $hObj_Old = _WinAPI_SelectObject($hDC_Bitmap, $hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Shutdown")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_DrawBuffer")
    GUIRegisterMsg($WM_PAINT, "_DrawBuffer")

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetBkColor($hDC_Bitmap, $iColorBGR_Not)
    _SetPixel($hDC_Bitmap, Random(0, $iSize - 1, 1), Random(0, $iSize - 1, 1), $iColorBGR_Seed)
    _DrawBuffer()

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $iCount
    Do
    $iX_Pos = Random(0, $iSize - 1, 1)
    $iY_Pos = Random(0, $iSize - 1, 1)
    Until _GetPixel($hDC_Bitmap, $iX_Pos, $iY_Pos) = $iColorBGR_Not

    [/autoit] [autoit][/autoit] [autoit]

    While True
    _SetPixel($hDC_Window, $iX_Pos, $iY_Pos, $iColorBGR_Mov)

    [/autoit] [autoit][/autoit] [autoit]

    $iX_Dir = Random(-1, 1, 1)
    $iY_Dir = Random(-1, 1, 1)
    If $iX_Dir = 0 And $iY_Dir = 0 Then ContinueLoop

    [/autoit] [autoit][/autoit] [autoit]

    If $iX_Pos + $iX_Dir < 0 Or $iX_Pos + $iX_Dir >= $iSize Or $iY_Pos + $iY_Dir < 0 Or $iY_Pos + $iY_Dir >= $iSize Then
    _DrawBuffer()
    $i -= 1
    ExitLoop
    Else
    If _GetPixel($hDC_Bitmap, $iX_Pos + $iX_Dir, $iY_Pos + $iY_Dir) <> $iColorBGR_Not Then
    _SetPixel($hDC_Bitmap, $iX_Pos, $iY_Pos, $iColorBGR_Set)
    _DrawBuffer()
    ExitLoop
    Else
    $iX_Pos += $iX_Dir
    $iY_Pos += $iY_Dir
    EndIf
    EndIf
    WEnd
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $hBitmapTmp = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    If Not StringRegExp($sFile, "\.bmp\z") Then $sFile &= ".bmp"
    _GDIPlus_ImageSaveToFile($hBitmapTmp, $sFile)
    _GDIPlus_ImageDispose($hBitmapTmp)
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _SetPixel($hDC, $iX, $iY, $iColor)
    DllCall($hDll_GDI32, 'INT', 'SetPixelV', 'HWND', $hDC, 'INT', $iX, 'INT', $iY, 'DWORD', $iColor)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetPixel($hDC, $iX, $iY)
    $aRet = DllCall($hDll_GDI32, 'DWORD', 'GetPixel', 'HWND', $hDC, 'INT', $iX, 'INT', $iY)
    Return $aRet[0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawBuffer()
    DllCall($hDll_GDI32, "BOOL", "BitBlt", "HANDLE", $hDC_Window, "INT", 0, "INT", 0, "INT", $iSize, "INT", $iSize, "HANDLE", $hDC_Bitmap, "INT", 0, "INT", 0, "DWORD", $SRCCOPY)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Shutdown()
    _WinAPI_SelectObject($hDC_Bitmap, $hObj_Old)
    _WinAPI_ReleaseDC($hWnd, $hDC_Window)
    _WinAPI_DeleteDC($hDC_Bitmap)
    _WinAPI_DeleteObject($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    DllClose($hDll_GDI32)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    Exit
    EndFunc

    [/autoit]


    Diese Variante braucht allerdings am Anfang so ewig um überhaupt mal zu treffen, dass ich den Weg den die Pixel zurücklegen auch temporär einfärben lasse um mich zu versichern, dass überhaupt etwas passiert :D.

    Edit: Hab noch 2 Bilder angehängt, eins von meinem Programm [Rechts] und eins von TheLuBus [Links] (musste ich per Screenshot erstellen).
    Edit2: Hab noch eine kleine Farbspielerei angehängt

  • Hi,

    Zitat von name22

    Viel schneller lässt sich dieser Algorithmus mit AutoIt nicht umsetzen

    Na, da steig ich doch in den Ring! 8o

    Bitmaps(und somit Pixel) kann man auch mittels einer Struct beschreiben/lesen.
    Da dllstructsetdata() / dllstructgetdata() über den dicken Daumen ca.10x schneller ist als Setpixel()/Getpixel() holt man so schon ca. Faktor 3 in der Gesamtgeschwindigkeit heraus.

    Btw. eine sehr feine Idee von dir, den "temporären" Weg direkt in den Fenster_DC zu SetPixel()n, und dann diesen DC dann wieder mit dem Ergebnisbild zu überschreiben :thumbup:

    Zitat

    Aber am Algorithmus den ich verwende lässt sich sicherlich noch feilen

    Bei der Umsetzung in eine Compilersprache wäre beim Algorithmus noch einiges rauszuholen.
    z.B. könnte man die "Suchschleife"

    [autoit]

    Do
    $iX_Pos = Random(0, $iSize - 1, 1)
    $iY_Pos = Random(0, $iSize - 1, 1)
    Until dllstructgetdata($struct,1,$ix_pos+$iy_pos*$isize)=$iColorBGR_Not

    [/autoit]

    ersetzen durch

    [autoit]

    $z=$iSize*$iSize-1 ;noch vor die For/to-Schleife
    Do
    $xy_Pos = Random(0, $z, 1)
    Until DllStructGetData($struct, 1, $xy_pos) = $iColorBGR_Not
    $iY_pos=int($xy_pos/$isize)
    $iX_pos=$xy_Pos-$iy_pos*$isize

    [/autoit]

    Ein Random() ist Laufzeittechnisch SEHR teuer, das würde bei einer Compilersprache also sehr viel bringen! Aber bei AutoIt frisst der Interpreter durch die zusätzliche Zeile Code den Vorteil fast vollkommen wieder auf....

    Aber ich denke auch, so langsam ist das Ende der Fahnenstange erreicht :rolleyes:
    Sehr viel schneller wirds mit AutoIt wohl nicht mehr werden.....

    Mein Umbau deines Codes:

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ; -Author: name22 (http://www.autoit.de)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hDll_GDI32 = DllOpen("gdi32.dll")
    Global $iX_Pos, $iY_Pos, $iX_Dir, $iY_Dir

    [/autoit] [autoit][/autoit] [autoit]

    Global $sFile = FileSaveDialog("Save Picture", "", "Bitmap (*.bmp)")
    If @error Then Exit

    [/autoit] [autoit][/autoit] [autoit]

    Global $iCount = 10000
    Global $iSize = 200

    [/autoit] [autoit][/autoit] [autoit]

    Global $iColorBGR_Seed = 0x000000FF
    Global $iColorBGR_Not = 0x00000000
    Global $iColorBGR_Set = 0x00FF0000
    Global $iColorBGR_Mov = 0x00f0f0f0

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Brownian Tree", $iSize, $iSize)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $hDC_Window = _WinAPI_GetDC($hWnd)
    ;~ $hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
    ;~ $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iSize, $iSize)
    ;~ $hObj_Old = _WinAPI_SelectObject($hDC_Bitmap, $hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Shutdown")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
    GUISetOnEvent($GUI_EVENT_RESTORE, "_DrawBuffer")
    GUIRegisterMsg($WM_PAINT, "_DrawBuffer")

    [/autoit] [autoit][/autoit] [autoit]

    ;buffer erstellen
    Global $ptr, $hbitmap
    $hdc_bitmap = _CreateNewBmp32($iSize, $iSize, $ptr, $hbitmap)

    [/autoit] [autoit][/autoit] [autoit]

    $struct = DllStructCreate("dword [" & $iSize * $iSize & "]", $ptr) ;per struct daten in bitmap schreiben

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_SetBkColor($hdc_bitmap, $iColorBGR_Not)
    _SetPixel($hdc_bitmap, $iSize / 2, $iSize / 2, $iColorBGR_Seed)
    _DrawBuffer()

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $iCount
    Do
    $iX_Pos = Random(0, $iSize - 1, 1)
    $iY_Pos = Random(0, $iSize - 1, 1)
    Until dllstructgetdata($struct,1,$ix_pos+$iy_pos*$isize)=$iColorBGR_Not;_GetPixel($hDC_Bitmap, $iX_Pos, $iY_Pos) = $iColorBGR_Not

    [/autoit] [autoit][/autoit] [autoit]

    While True
    ;_SetPixel($hDC_Window, $iX_Pos, $iY_Pos, $iColorBGR_Mov)

    [/autoit] [autoit][/autoit] [autoit]

    $iX_Dir = Random(-1, 1, 1)
    $iY_Dir = Random(-1, 1, 1)
    If $iX_Dir = 0 And $iY_Dir = 0 Then ContinueLoop

    [/autoit] [autoit][/autoit] [autoit]

    If $iX_Pos + $iX_Dir < 0 Or $iX_Pos + $iX_Dir >= $iSize Or $iY_Pos + $iY_Dir < 0 Or $iY_Pos + $iY_Dir >= $iSize Then
    _DrawBuffer()
    $i -= 1
    ExitLoop

    [/autoit] [autoit][/autoit] [autoit]

    Else
    If DllStructGetData($struct, 1, ($iX_Pos + $iX_Dir) + ($iY_Pos + $iY_Dir) * $iSize) <> $iColorBGR_Not Then;_GetPixel($hDC_Bitmap, $iX_Pos + $iX_Dir, $iY_Pos + $iY_Dir) <> $iColorBGR_Not Then
    DllStructSetData($struct, 1, $iColorBGR_Set, $iX_Pos + $iY_Pos * $iSize)
    ;_SetPixel($hDC_Bitmap, $iX_Pos, $iY_Pos, $iColorBGR_Set)
    _DrawBuffer()
    ExitLoop
    Else
    $iX_Pos += $iX_Dir
    $iY_Pos += $iY_Dir
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndIf
    WEnd
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $hBitmapTmp = _GDIPlus_BitmapCreateFromHBITMAP($hbitmap)
    If Not StringRegExp($sFile, "\.bmp\z") Then $sFile &= ".bmp"
    _GDIPlus_ImageSaveToFile($hBitmapTmp, $sFile)
    _GDIPlus_ImageDispose($hBitmapTmp)
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    ShellExecute($sFile)

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _SetPixel($hDC, $iX, $iY, $iColor)
    DllCall($hDll_GDI32, 'INT', 'SetPixelV', 'HWND', $hDC, 'INT', $iX, 'INT', $iY, 'DWORD', $iColor)
    EndFunc ;==>_SetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetPixel($hDC, $iX, $iY)
    $aRet = DllCall($hDll_GDI32, 'DWORD', 'GetPixel', 'HWND', $hDC, 'INT', $iX, 'INT', $iY)
    Return $aRet[0]
    EndFunc ;==>_GetPixel

    [/autoit] [autoit][/autoit] [autoit]

    Func _DrawBuffer()
    DllCall($hDll_GDI32, "BOOL", "BitBlt", "HANDLE", $hDC_Window, "INT", 0, "INT", 0, "INT", $iSize, "INT", $iSize, "HANDLE", $hdc_bitmap, "INT", 0, "INT", 0, "DWORD", $SRCCOPY)
    EndFunc ;==>_DrawBuffer

    [/autoit] [autoit][/autoit] [autoit]

    Func _Shutdown()
    ; _WinAPI_SelectObject($hDC_Bitmap, $hObj_Old)
    _WinAPI_ReleaseDC($hWnd, $hDC_Window)
    _WinAPI_DeleteDC($hdc_bitmap)
    _WinAPI_DeleteObject($hbitmap)

    [/autoit] [autoit][/autoit] [autoit]

    DllClose($hDll_GDI32)
    EndFunc ;==>_Shutdown

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    Exit
    EndFunc ;==>_Close

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateNewBmp32($iwidth, $iheight, ByRef $ptr, ByRef $hbmp) ;erstellt leere 32-bit-Bitmap; Rückgabe $HDC und $ptr und handle auf die Bitmapdaten
    $hcdc = _WinAPI_CreateCompatibleDC(0) ;Desktop-Kompatiblen DeviceContext erstellen lassen
    $tBMI = DllStructCreate($tagBITMAPINFO) ;Struktur der Bitmapinfo erstellen und Daten eintragen
    DllStructSetData($tBMI, "Size", DllStructGetSize($tBMI) - 4);Structgröße abzüglich der Daten für die Palette
    DllStructSetData($tBMI, "Width", $iwidth)
    DllStructSetData($tBMI, "Height", -$iheight) ;minus =standard = bottomup
    DllStructSetData($tBMI, "Planes", 1)
    DllStructSetData($tBMI, "BitCount", 32) ;32 Bit = 4 Bytes => AABBGGRR
    $adib = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
    $hbmp = $adib[0] ;hbitmap handle auf die Bitmap, auch per GDI+ zu verwenden
    $ptr = $adib[4] ;pointer auf den Anfang der Bitmapdaten, vom Assembler verwendet
    _WinAPI_SelectObject($hcdc, $hbmp) ;objekt hbitmap in DC
    Return $hcdc ;DC der Bitmap zurückgeben
    EndFunc ;==>_CreateNewBmp32

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Schickes Script Andy :D. Das ist doch wesentlich schneller als die bisherigen Versionen.
    Ich hatte die Idee, dass man doch den Abstand den die Partikel zum Seed haben begrenzen könnte. Man müsste genügend Platz lassen, um das Ergebnis möglichst wenig zu beeinträchtigen und den Maximalabstand mit jedem neuen Pixel, der weiter entfernt gesetzt wird als alle Bisherigen, vergößern. Aber ich weiß nicht ob sich das im Code effizient umsetzen lässt.

  • Teamwork rulez!

    [autoit]

    $z=$isize/2 ;mittelpunkt

    [/autoit][autoit][/autoit][autoit]

    For $i = 1 To $iCount
    Do
    $iX_Pos = Random($z-2-(sqrt($i)), $z+2+(sqrt($i)), 1)
    $iY_Pos = Random($z-2-(sqrt($i)), $z+2+(sqrt($i)), 1)
    Until dllstructgetdata($struct,1,$ix_pos+$iy_pos*$isize)=$iColorBGR_Not;_GetPixel($hDC_Bitmap, $iX_Pos, $iY_Pos) = $iColorBGR_Not

    [/autoit]

    :rock:

  • das hier bringt nochmal zusätzlich speed

    Spoiler anzeigen
    [autoit]

    $z=$isize/2 ;mittelpunkt

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $iCount
    $p=$z-2-(sqrt($i))
    $q=$z+2+(sqrt($i))
    Do
    $iX_Pos = Random($p,$q,1)
    $iY_Pos = Random($p,$q,1)

    [/autoit] [autoit][/autoit] [autoit]

    Until dllstructgetdata($struct,1,$ix_pos+$iy_pos*$isize)=$iColorBGR_Not;_GetPixel($hDC_Bitmap, $iX_Pos, $iY_Pos) = $iColorBGR_Not
    _SetPixel($hDC_Window, $p,$q, $iColorBGR_Mov)
    While True
    ;_SetPixel($hDC_Window, $iX_Pos, $iY_Pos, $iColorBGR_Mov)

    [/autoit] [autoit][/autoit] [autoit]

    $iX_Dir = Random(-1, 1, 1)
    $iY_Dir = Random(-1, 1, 1)
    If $iX_Dir = 0 And $iY_Dir = 0 Then ContinueLoop

    [/autoit] [autoit][/autoit] [autoit]

    If $iX_Pos + $iX_Dir < $p Or $iX_Pos + $iX_Dir >= $q Or $iY_Pos + $iY_Dir < $p Or $iY_Pos + $iY_Dir >= $q Then
    _DrawBuffer()
    $i -= 1
    ExitLoop

    [/autoit] [autoit][/autoit] [autoit]

    Else
    If DllStructGetData($struct, 1, ($iX_Pos + $iX_Dir) + ($iY_Pos + $iY_Dir) * $iSize) <> $iColorBGR_Not Then;_GetPixel($hDC_Bitmap, $iX_Pos + $iX_Dir, $iY_Pos + $iY_Dir) <> $iColorBGR_Not Then
    DllStructSetData($struct, 1, $iColorBGR_Set, $iX_Pos + $iY_Pos * $iSize)
    ;_SetPixel($hDC_Bitmap, $iX_Pos, $iY_Pos, $iColorBGR_Set)
    _DrawBuffer()
    ExitLoop
    Else
    $iX_Pos += $iX_Dir
    $iY_Pos += $iY_Dir
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    EndIf
    WEnd
    Next

    [/autoit]

    aus dem Bauch raus würde ich zum optimieren eher auf eine logaritmische Funktion statt der quadratischen gehen...also e-Funktion statt Wurzel....ob das aber was bringt^^

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    Einmal editiert, zuletzt von Andy (29. November 2012 um 19:15)