• Da ich mal wieder Lust hatte ein bisschen in AutoIt zu spielen, und mein Lehrer mir die Aufgabe für Delphi gab, dachte ich ich portiere sie einfach mal nach AutoIt.
    Ist nichts wirklich besonderes, eigentlich relativ einfach und simpel zu lösen.
    Kurze Rede - Kürzerer Sinn, hier das Script:

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    _GDIPlus_Startup()
    Global $pi = 3.14159265358979
    Global $hGui = GUICreate("Recursive Tree", 500, 500)
    Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    GUIsetState(@SW_SHOW)

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

    _GDIPlus_GraphicsDrawLine($hGraphic, 250, 500, 250, 250)
    RecursiveTree(250, 250, 0, 35, 5, 0, 50, 3)

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

    While Sleep(10)
    _GDIPlus_GraphicsDrawLine($hGraphic, 250, 500, 250, 250)
    Switch GuiGetMsg()
    Case -3
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    WEnd

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

    ;Parameter:
    ;$AltX - Start X
    ;$AltY - Start Y
    ;$nWinkel - 0
    ;$vWinkel - Um welche Zahl der Winkel erhöht / erniedrigt wird
    ;$Tiefe - Wie viele Ebenen der Baum hat
    ;$AnzahlAktuell - 0
    ;$Length - Länge des Anfangsastes
    ;$EllipseWidth - Größe der Knoten
    Func RecursiveTree($AltX, $AltY, $nWinkel, $vWinkel, $Tiefe, $AnzahlAktuell, $Length, $EllipseWidth)
    Local $newX, $newY, $newLength
    If ($Tiefe <> $AnzahlAktuell) Then
    ;Sinus = Y
    ;Cosinus = X
    $newLength = $Length - 5
    $newX = sin(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    $newY = cos(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel + $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    $newX = sin(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    $newY = cos(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel - $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    EndIf
    EndFunc ;==>RecursiveTree

    [/autoit]


    Und ein Bild:
    [Blockierte Grafik: http://i.epvpimg.com/5JNGd.png]

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal

  • sehr schön, man kann auch wunderbar "zufällige" Bäume erstellen

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    _GDIPlus_Startup()
    Global $pi = 3.14159265358979
    Global $hGui = GUICreate("Recursive Tree", 500, 500)
    Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    GUIsetState(@SW_SHOW)

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

    _GDIPlus_GraphicsDrawLine($hGraphic, 250, 500, 250, 250)
    RecursiveTree2(250, 250, 0, 35, 10, 0, 50, 3)

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

    While Sleep(10)
    _GDIPlus_GraphicsDrawLine($hGraphic, 250, 500, 250, 250)
    Switch GuiGetMsg()
    Case -3
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    WEnd

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

    ;Parameter:
    ;$AltX - Start X
    ;$AltY - Start Y
    ;$nWinkel - 0
    ;$vWinkel - Um welche Zahl der Winkel erhöht / erniedrigt wird
    ;$Tiefe - Wie viele Ebenen der Baum hat
    ;$AnzahlAktuell - 0
    ;$Length - Länge des Anfangsastes
    ;$EllipseWidth - Größe der Knoten
    Func RecursiveTree($AltX, $AltY, $nWinkel, $vWinkel, $Tiefe, $AnzahlAktuell, $Length, $EllipseWidth)
    Local $newX, $newY, $newLength
    If ($Tiefe <> $AnzahlAktuell) Then
    ;Sinus = Y
    ;Cosinus = X
    $newLength = $Length - 5
    $newX = sin(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    $newY = cos(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel + $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    $newX = sin(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    $newY = cos(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel - $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    EndIf
    EndFunc ;==>RecursiveTree

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

    Func RecursiveTree2($AltX, $AltY, $nWinkel, $vWinkel, $Tiefe, $AnzahlAktuell, $Length, $EllipseWidth)
    Local $newX, $newY, $newLength
    If ($Tiefe <> $AnzahlAktuell) Then
    ;Sinus = Y
    ;Cosinus = X
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)
    $newX = sin(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newY = cos(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel + $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newX = sin(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newY = cos(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel - $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)
    $newX = sin(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newY = cos(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel + $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newX = sin(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newY = cos(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel - $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)
    $newX = sin(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newY = cos(($nWinkel + $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel + $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newX = sin(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    $newLength = $Length - random(0,25,1)
    $nWinkel = random(10,50,1)
    $vWinkel = random(10,50,1)

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

    $newY = cos(($nWinkel - $vWinkel) * ($pi / 180)) * $newLength * -1
    _GDIPlus_GraphicsDrawLine($hGraphic, $AltX, $AltY, $AltX + $newX, $AltY + $newY)
    _GDIPlus_GraphicsDrawEllipse($hGraphic, $AltX + $newX - $EllipseWidth, $AltY + $newY - $EllipseWidth, $EllipseWidth*2, $EllipseWidth*2)
    RecursiveTree($AltX + $newX, $AltY + $newY, $nWinkel - $vWinkel, $vWinkel, $Tiefe, $AnzahlAktuell + 1, $newLength, $EllipseWidth)

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

    EndIf
    EndFunc ;==>RecursiveTree

    [/autoit]
  • :thumbup: wesentlich schneller als von mir das Script (dafür wesentlich länger :D)
    Sieht gut aus, aber das (liegt nicht an dir) langweilige Anfangsmuster bleibt ja (leider) :D

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal