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
#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)
_GDIPlus_GraphicsDrawLine($hGraphic, 250, 500, 250, 250)
RecursiveTree(250, 250, 0, 35, 5, 0, 50, 3)
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
;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
Und ein Bild:
[Blockierte Grafik: http://i.epvpimg.com/5JNGd.png]