Rekursion - Sierpinski-Dreieck - GDI+

  • Liebe Community,

    vor kurzen habe ich mal als ich mir die Rekursion in Java angeeignet habe das Sierpinski-Dreieck programmiert. Wer nicht weiß was das Sierpinski-Dreieck ist, der findet hier etwas dazu.
    Ich wollte das gleiche nochmal in AutoIt verfassen und hier ist das fertige Script.

    Man kann einstellen ob das Dreieck nur Schwarz/Weiß dargestellt werden soll oder mit unterschiedlichen Farben (hier: Rot/Blau/Grün/Weiß).
    Und man kann noch die Anzahl der Runden festlegen, also wie oft das Dreieck zerteilt werden soll.

    Nur damit ihr nicht eine zu große Zahl eingebt und euer Computer dann nachhechelt, auf meinem PC ist "7" eine gute Anzahl von Runden. Ich brauche dafür ca. 10 Sekunden.
    Außerdem wenn man die Anzahl von Runden zu hoch einstellt, dann sieht es nicht mehr besonders gut aus :).

    Also ich hoffe es gefällt euch.

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

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

    AutoIt Version: 3.3.6.1
    Author: Bakku

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

    Script Function:
    Sierpinski-Dreieck

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

    #ce ----------------------------------------------------------------------------

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

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>

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

    Opt('GUIOnEventMode', 1)
    Opt('MustDeclareVars', 1)

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

    _GDIPlus_Startup()

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

    Global $sTitle = "Sierpinski - by Bakku (http://www.autoit.de)"
    Global $iWidth = 500
    Global $iHeight = 400
    Global $hWnd, $hGUI
    Global $hGraphics, $hBitmap, $hBuffer
    Global $hBrushWhite, $hBrushRed, $hBrushGreen, $hBrushBlue, $hBrushBlack
    Global $aStartCoordinates[4][2] ; Coordinates for the first Polygon
    Global $bRandomBrush ; Should the colors just be black and white or random
    Global $hGUIPreferences, $hGenerate, $hInput, $hCheckbox
    Global $bPreferences = True
    Global $iN ; Amount of Rounds

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

    $aStartCoordinates[0][0] = 3
    $aStartCoordinates[1][0] = 250
    $aStartCoordinates[1][1] = 50
    $aStartCoordinates[2][0] = 50
    $aStartCoordinates[2][1] = 350
    $aStartCoordinates[3][0] = 450
    $aStartCoordinates[3][1] = 350

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

    ;--------------------------------------Sierpinski-GUI Creation-----------------------------------------------------------------------------

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

    $hGUI = GUICreate($sTitle, $iWidth, $iHeight)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

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

    $hWnd = WinGetHandle($sTitle)

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

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
    $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    $hBrushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hBrushRed = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $hBrushGreen = _GDIPlus_BrushCreateSolid(0xFF00FF00)
    $hBrushBlue = _GDIPlus_BrushCreateSolid(0xFF0000FF)
    $hBrushBlack = _GDIPlus_BrushCreateSolid(0xFF000000)

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

    _GDIPlus_GraphicsClear($hBuffer, 0xFF000000)

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

    _GDIPlus_GraphicsFillPolygon($hBuffer, $aStartCoordinates, $hBrushWhite)

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

    GUIRegisterMsg($WM_PAINT, "WM_PAINT")

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

    ;----------------------------------------END Sierpinski-GUI --------------------------------------------------------------------------------------

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

    ;---------------------------------------Preferences-GUI-------------------------------------------------------------------------------------------

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

    $hGUIPreferences = GUICreate("Generate", 200, 200)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

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

    $hGenerate = GUICtrlCreateButton("Generate", 50, 150, 100, 25)
    GUICtrlSetOnEvent($hGenerate, "_Generate")

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

    $hCheckbox = GUICtrlCreateCheckbox("Black/White", 60, 20)

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

    GUICtrlCreateLabel("Rounds:", 60, 70)

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

    $hInput = GUICtrlCreateInput("", 110, 68, 20, 20, $ES_NUMBER)

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

    GUISetState(@SW_SHOW, $hGUIPreferences)

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

    ; As long as $bPreferences is true, the Preferences-GUI is visible and $hGUI not
    While ($bPreferences)

    WEnd

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

    GUISetState(@SW_HIDE, $hGUIPreferences)

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

    ;---------------------------------------END Preferences-GUI-----------------------------------------------------------------------------------------

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

    GUISetState(@SW_SHOW, $hGUI)

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

    ; Starts the first Sierpinski-Round
    Sierpinski($aStartCoordinates[1][0], $aStartCoordinates[1][1], $aStartCoordinates[2][0], $aStartCoordinates[2][1], $aStartCoordinates[3][0], $aStartCoordinates[3][1], $iN)

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

    While 1 * Sleep(10)

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

    WEnd

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

    Func Sierpinski($iX1, $iY1, $iX2, $iY2, $iX3, $iY3, $n)
    ; If $n == 0 --> end of the sierpinski-triangle
    If ($n > 0) Then
    Local $aReturnCoordinates[4][2]

    $aReturnCoordinates[0][0] = 3

    ; ax = (x1 + x2) / 2
    ; ay = (y1 + y2) / 2
    $aReturnCoordinates[1][0] = ($iX1 + $iX2) / 2
    $aReturnCoordinates[1][1] = ($iY1 + $iY2) / 2

    ; bx = (x2 + x3) / 2
    ; by = (y2 + y3) / 2
    $aReturnCoordinates[2][0] = ($iX2 + $iX3) / 2
    $aReturnCoordinates[2][1] = ($iY2 + $iY3) / 2

    ; cx = (x1 + x3) / 2
    ; cx = (y1 + y3) / 2
    $aReturnCoordinates[3][0] = ($iX1 + $iX3) / 2
    $aReturnCoordinates[3][1] = ($iY1 + $iY3) / 2

    _GDIPlus_GraphicsFillPolygon($hBuffer, $aReturnCoordinates, _RandomBrush())
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_INTERNALPAINT)

    ; sierpinski-function calls for the new three triangles
    Sierpinski($iX1, $iY1, $aReturnCoordinates[1][0], $aReturnCoordinates[1][1], $aReturnCoordinates[3][0], $aReturnCoordinates[3][1], $n - 1)
    Sierpinski($iX2, $iY2, $aReturnCoordinates[1][0], $aReturnCoordinates[1][1], $aReturnCoordinates[2][0], $aReturnCoordinates[2][1], $n - 1)
    Sierpinski($iX3, $iY3, $aReturnCoordinates[2][0], $aReturnCoordinates[2][1], $aReturnCoordinates[3][0], $aReturnCoordinates[3][1], $n - 1)
    EndIf
    EndFunc

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

    Func _RandomBrush()
    If ($bRandomBrush == True) Then
    Local $Rnd

    $Rnd = Random(1, 4, 1)

    Switch $Rnd
    Case 1
    Return $hBrushWhite

    Case 2
    Return $hBrushRed

    Case 3
    Return $hBrushGreen

    Case 4
    Return $hBrushBlue
    EndSwitch
    EndIf
    EndFunc

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

    Func _Generate()
    If (GUICtrlRead($hInput) == "") Then
    MsgBox(16, "Error", "No number of rounds given!")
    Return 0
    EndIf

    $iN = GUICtrlRead($hInput)

    If (GUICtrlRead($hCheckbox) == $GUI_CHECKED) Then
    $bRandomBrush = False
    Else
    $bRandomBrush = True
    EndIf

    $bPreferences = False
    EndFunc

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

    Func WM_PAINT()
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    EndFunc

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

    Func _Exit()
    _GDIPlus_BrushDispose($hBrushBlack)
    _GDIPlus_BrushDispose($hBrushBlue)
    _GDIPlus_BrushDispose($hBrushGreen)
    _GDIPlus_BrushDispose($hBrushRed)
    _GDIPlus_BrushDispose($hBrushWhite)
    _GDIPlus_ImageDispose($hBuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]
  • Sehr beändstigend... ich beschäftige mich auch mit Java im Moment und Frakturen :huh: Und das L-System. Gut geworden, ich finds schön.

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

  • Ich habe auch vor langer Zeit einige L-Systeme implementiert: GDI+ Beispiele (#05 - L-System Fraktale)

    Da der Code relativ alt ist, kann es sein, dass man ihn anpassen muss, damit er sauber läuft. Hier die Version, das mit der aktuellen Version läuft:

    Spoiler anzeigen
    [autoit]


    ;coded by UEZ 2009-01-17
    #AutoIt3Wrapper_Run_Obfuscator=y
    #Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
    #AutoIt3Wrapper_UseUpx=n
    ;~ #AutoIt3Wrapper_Run_After=upx.exe --best "%out%"
    #AutoIt3Wrapper_Run_After=upx.exe --ultra-brute "%out%"
    #AutoIt3Wrapper_Run_After=del "%scriptdir%\%scriptfile%_Obfuscated.au3"

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

    #include <Array.au3>
    #include <GDIPlus.au3>
    #Include <Misc.au3>

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

    Opt('MustDeclareVars', 1)
    Opt("GUIOnEventMode", 1)

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

    Global $dll = DllOpen("user32.dll")
    Global Const $Pi = 4 * ATan(1)
    Global Const $Pi_Div_180 = $Pi / 180
    Global Const $width = 800
    Global Const $height = 600
    Global $hGUI, $hWnd, $hGraphic, $Bitmap, $Pen
    Global $angle = 0, $x1, $y1, $x2, $y2, $random
    Global $length, $depth, $dir, $degree, $dist_rel
    Global $font_size, $String_Format, $Font_Family, $Font, $Text_Layout, $Brush, $text

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

    $hGUI = GUICreate("GDI+: L-System Fractals by UEZ 2009 (press F9 to save current image)", $width, $height)
    GUISetState(@SW_SHOW)

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

    GUISetOnEvent(-3, "_Exit")

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

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    $Pen = _GDIPlus_PenCreate(0, 1)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ; AntiAlias

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

    $font_size = 7
    $String_Format = _GDIPlus_StringFormatCreate ()
    $Font_Family = _GDIPlus_FontFamilyCreate ("Arial")
    $Font = _GDIPlus_FontCreate ($Font_Family, $font_size, 2)
    $Brush = _GDIPlus_BrushCreateSolid (0xDF000000) ;text color

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

    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

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

    $random = Random(1, 11, 1)

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

    AdlibRegister("Save_PIC", 50)

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

    While 1
    Switch $random
    Case 1 ;Dragon Curve
    $x1 = $width / 4.2
    $y1 = $height / 2.8
    $length = 500
    $depth = Random(6, 18, 1)
    $dir = 1
    $angle = 0
    $text = "Dragon Curve, Recursion Depth = " & $depth
    Draw_Text()
    Dragon($length, $depth, $dir)
    Case 2 ;Levy-C Curve
    $x1 = $width / 3.65
    $y1 = $height / 2.875
    $length = 475
    $depth = Random(6, 18, 1)
    $dir = 1
    $angle = 0
    $text = "Levy-C Curve, Recursion Depth = " & $depth
    Draw_Text()
    Levy_C($length, $depth, $dir)
    Case 3 ;Koch Curve
    $x1 = $width / 5.3
    $y1 = $height / 1.35
    $x2 = ""
    $y2 = ""
    $length = 500
    $depth = Random(2, 8, 1)
    $dir = 1
    $angle = 0
    $text = "Koch Curve, Recursion Depth = " & $depth
    Draw_Text()
    Koch($length, $depth, $dir) ;F
    Turn(-$dir * 2 * $degree) ;--
    Koch($length, $depth, $dir) ;F
    Turn(-$dir * 2 * $degree) ;--
    Koch($length, $depth, $dir) ;F
    Case 4 ;Peano Curve
    $x1 = $width / 8
    $y1 = $height / 2
    $length = 600
    $depth = Random(2, 5, 1)
    $dir = 1
    $angle = 0
    $text = "Peano Curve, Recursion Depth = " & $depth
    Draw_Text()
    Peano($length, $depth, $dir)
    Case 5 ;Triangle
    $x1 = $width / 10.8
    $y1 = $height / 1.03
    $length = 1300
    $depth = Random(2, 10, 1)
    $dir = 1
    $angle = 0
    $text = "Triangle, Recursion Depth = " & $depth
    Draw_Text()
    Triangle($length, $depth, $dir)
    Case 6 ;Arrowhead Curve
    $x1 = $width / 10.80
    $y1 = $height / 1.05
    $length = 650
    $depth = Random(3, 9, 1)
    $dir = 1
    $angle = 0
    $text = "Arrowhead Curve, Recursion Depth = " & $depth
    Draw_Text()
    Arrowhead_R($length, $depth, $dir) ;R
    Case 7 ;Penta Plexity
    $x1 = $width / 3.55
    $y1 = $height / 15
    $length = 350
    $depth = Random(1, 6, 1)
    $dir = 1
    $angle = 0
    $text = "Penta Plexity, Recursion Depth = " & $depth
    Draw_Text()
    ;F++F++F++F++F
    Penta_Plexity($length, $depth, $dir) ;F
    Turn($dir * 2 * $degree) ;++
    Penta_Plexity($length, $depth, $dir) ;F
    Turn($dir * 2 * $degree) ;++
    Penta_Plexity($length, $depth, $dir) ;F
    Turn($dir * 2 * $degree) ;++
    Penta_Plexity($length, $depth, $dir) ;F
    Turn($dir * 2 * $degree) ;++
    Penta_Plexity($length, $depth, $dir) ;F
    Case 8 ;Sierpinski Carpet
    $x1 = $width / 8
    $y1 = $height / 2
    $length = 600
    $depth = Random(2, 6, 1)
    $dir = 1
    $angle = 0
    $text = "Sierpinski Carpet, Recursion Depth = " & $depth
    Draw_Text()
    Sierpinski_Carpet($length, $depth, $dir) ;F
    Case 9 ;Gosper Curve
    $depth = Random(4, 6, 1)
    $x1 = $width / 1.45
    $y1 = $height / 7 - $depth
    $length = 480
    $dir = 1
    $angle = 0
    $text = "Gosper Curve, Recursion Depth = " & $depth
    Draw_Text()
    Gosper_R($length, $depth, $dir) ;R
    Case 10 ;Sierpinski Triangle
    $x1 = $width / 10.666
    $y1 = $height / 1.05
    $length = 325
    $depth = Random(2, 9, 1)
    $dir = 1
    $angle = 0
    $text = "Sierpinski Triangle, Recursion Depth = " & $depth
    Draw_Text()
    ;FXF--FF--FF
    Sierpinski_F($length, $depth, $dir) ;F
    Sierpinski_X($length, $depth, $dir) ;X
    Sierpinski_F($length, $depth, $dir) ;F
    Turn(-$dir * 2 * $degree) ;--
    Sierpinski_F($length, $depth, $dir) ;F
    Sierpinski_F($length, $depth, $dir) ;F
    Turn(-$dir * 2 * $degree) ;--
    Sierpinski_F($length, $depth, $dir) ;F
    Sierpinski_F($length, $depth, $dir) ;F
    Case 11 ;Pythagoras Tree
    $x1 = $width / 2
    $y1 = $height / 1.1
    $length = 110
    $depth = Random(5, 15, 1)
    $dir = 1
    $angle = 5
    $text = "Pythagoras Tree, Recursion Depth = " & $depth
    Draw_Text()
    Pythagoras($length, $depth, $dir)
    EndSwitch
    $random += 1
    If $random = 12 Then $random = 1
    Sleep(4000)
    _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)
    Wend

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

    Func Pythagoras($length, $split, $dir)

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Pythagoras_Square($length)
    Else
    $dist_rel = Sqrt(3) / 2
    $degree = 30
    Pythagoras_Square($length)
    Forward_Only($length)
    Turn(-$dir * 1 * $degree)
    Pythagoras($length * $dist_rel, $split - 1, 1)
    Turn($dir * 3 * $degree)
    Forward_Only($length * $dist_rel)
    Pythagoras($length / 2, $split - 1, 1)
    Forward_Only(-$length * $dist_rel)
    Turn(-$dir * 2 * $degree)
    Forward_Only(-$length)
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Pythagoras_Square($length)
    Local $i
    For $i = 1 To 4
    Draw_and_Forward($length)
    Turn($dir * 90)
    Next
    EndFunc

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

    Func Sierpinski_X($length, $split, $dir)
    ;FXF--FF--FF
    ;X -> --FXF++FXF++FXF--
    ;F -> FF

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    ;~ Draw_and_Forward($length)
    Else
    $dist_rel = 2
    $degree = 60
    Turn(-$dir * 2 * $degree) ;--
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    Sierpinski_X($length / $dist_rel, $split - 1, 1) ;X
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * 2 * $degree) ;++
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    Sierpinski_X($length / $dist_rel, $split - 1, 1) ;X
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * 2 * $degree) ;++
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    Sierpinski_X($length / $dist_rel, $split - 1, 1) ;X
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 2 * $degree) ;--
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Sierpinski_F($length, $split, $dir)
    ;FXF--FF--FF
    ;X -> --FXF++FXF++FXF--
    ;F -> FF

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = 2
    $degree = 60
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    Sierpinski_F($length / $dist_rel, $split - 1, 1) ;F
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Gosper_R($length, $split, $dir)
    ;F -> R or F -> L
    ;R -> R+L++L-R--RR-L+
    ;L -> -R+LL++L+R--R-L

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = Sqrt(7)
    $degree = 60
    Gosper_R($length / $dist_rel, $split - 1, 1) ;R
    Turn($dir * 1 * $degree) ;+
    Gosper_L($length / $dist_rel, $split - 1, 1) ;L
    Turn($dir * 2 * $degree) ;++
    Gosper_L($length / $dist_rel, $split - 1, 1) ;L
    Turn(-$dir * 1 * $degree) ;-
    Gosper_R($length / $dist_rel, $split - 1, 1) ;R
    Turn(-$dir * 2 * $degree) ;--
    Gosper_R($length / $dist_rel, $split - 1, 1) ;R
    Gosper_R($length / $dist_rel, $split - 1, 1) ;R
    Turn(-$dir * 1 * $degree) ;-
    Gosper_L($length / $dist_rel, $split - 1, 1) ;L
    Turn($dir * 1 * $degree) ;+
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Gosper_L($length, $split, $dir)
    ;F -> R or F -> L
    ;R -> R+L++L-R--RR-L+
    ;L -> -R+LL++L+R--R-L

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = Sqrt(7)
    $degree = 60
    Turn(-$dir * 1 * $degree) ;-
    Gosper_R($length / $dist_rel, $split - 1, 1) ;R
    Turn($dir * 1 * $degree) ;+
    Gosper_L($length / $dist_rel, $split - 1, 1) ;L
    Gosper_L($length / $dist_rel, $split - 1, 1) ;L
    Turn($dir * 2 * $degree) ;++
    Gosper_L($length / $dist_rel, $split - 1, 1) ;L
    Turn($dir * 1 * $degree) ;+
    Gosper_R($length / $dist_rel, $split - 1, 1) ;R
    Turn(-$dir * 2 * $degree) ;--
    Gosper_R($length / $dist_rel, $split - 1, 1) ;R
    Turn(-$dir * 1 * $degree) ;-
    Gosper_L($length / $dist_rel, $split - 1, 1) ;L
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Sierpinski_Carpet($length, $split, $dir)
    ;F
    ;F -> F+F-F-FF-F-F-fF
    ;f -> fff

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = 3
    $degree = 90
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * 1 * $degree) ;+
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 1 * $degree) ;-
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 1 * $degree) ;-
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 1 * $degree) ;-
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 1 * $degree) ;-
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 1 * $degree) ;-
    Sierpinski_Carpet_Forward_Only($length / $dist_rel, $split - 1, 1) ;f
    Sierpinski_Carpet($length / $dist_rel, $split - 1, 1) ;F
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Sierpinski_Carpet_Forward_Only($length, $split, $dir) ;f
    ;F
    ;F -> F+F-F-FF-F-F-fF
    ;f -> fff
    Forward_Only($length / $dist_rel) ;f
    Forward_Only($length / $dist_rel) ;f
    Forward_Only($length / $dist_rel) ;f
    ;Sleep(0)
    EndFunc

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

    Func Penta_Plexity($length, $split, $dir)
    ;F++F++F++F++F
    ;F -> F++F++F|F-F++F

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = ((Sqrt(5) + 1) / 2)^2
    $degree = 36
    Penta_Plexity($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * 2 * $degree) ;++
    Penta_Plexity($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * 2 * $degree) ;++
    Penta_Plexity($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * 5 * $degree) ;180°
    Penta_Plexity($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 1 * $degree) ;-
    Penta_Plexity($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * 2 * $degree) ;++
    Penta_Plexity($length / $dist_rel, $split - 1, 1) ;F
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Arrowhead_R($length, $split, $dir)
    ;F -> R oder F -> L
    ;R -> -L+R+L-
    ;L -> +R-L-R+

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = 2
    $degree = 60
    Turn(-$dir * 1 * $degree) ;-
    Arrowhead_L($length / $dist_rel, $split - 1, 1) ;L
    Turn($dir * 1 * $degree) ;+
    Arrowhead_R($length / $dist_rel, $split - 1, 1) ;R
    Turn($dir * 1 * $degree) ;+
    Arrowhead_L($length / $dist_rel, $split - 1, 1) ;L
    Turn(-$dir * 1 * $degree) ;--
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Arrowhead_L($length, $split, $dir)
    ;F -> R oder F -> L
    ;R -> -L+R+L-
    ;L -> +R-L-R+

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = 2
    $degree = 60
    Turn($dir * 1 * $degree) ;+
    Arrowhead_R($length / $dist_rel, $split - 1, 1) ;R
    Turn(-$dir * 1 * $degree) ;-
    Arrowhead_L($length / $dist_rel, $split - 1, 1) ;L
    Turn(-$dir * 1 * $degree) ;-
    Arrowhead_R($length / $dist_rel, $split - 1, 1) ;R
    Turn($dir * 1 * $degree) ;+
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Triangle($length, $split, $dir)
    ;F--F--F
    ;F -> F--F--F--ff
    ;ff -> ff

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = 2
    $degree = 60
    Triangle($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 2 * $degree) ;--
    Triangle($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 2 * $degree) ;--
    Triangle($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 2 * $degree) ;--
    Forward_Only($length / $dist_rel) ;f
    Forward_Only($length / $dist_rel) ;f
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Dragon($length, $split, $dir)
    ;F -> R
    ;R -> +R--L+
    ;L -> -R++L-

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $degree = 45
    $dist_rel = Sqrt(2)
    Turn($dir * $degree) ;+
    Dragon($length / $dist_rel, $split - 1, 1) ;R
    Turn(-$dir * 2 * $degree) ;--
    Dragon($length / $dist_rel, $split - 1, -1) ;L
    Turn($dir * $degree) ;+
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Levy_C($length, $split, $dir)
    ;F
    ;F -> +F--F+

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $degree = 45
    $dist_rel = 1.45
    Turn($dir * $degree) ;+
    Levy_C($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 2 * $degree) ;--
    Levy_C($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * $degree) ;+
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Koch($length, $split, $dir)
    ;F--F--F
    ;F -> F+F--F+F

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = 3
    $degree = 60
    Koch($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * $degree) ;+
    Koch($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * 2 * $degree) ;--
    Koch($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * $degree) ;+
    Koch($length / $dist_rel, $split - 1, 1) ;F
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Peano($length, $split, $dir)
    ;F
    ;F -> F-F+F+F+F-F-F-F+F

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

    If _IsPressed("20", $dll) Then ;hold pressed spacebar to abort current drawing
    $split = 0
    $dir = 0
    $length = 0
    EndIf
    If $split = 0 Then
    Draw_and_Forward($length)
    Else
    $dist_rel = 3
    $degree = 90
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * $degree) ;-
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * $degree) ;+
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * $degree) ;+
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * $degree) ;+
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * $degree) ;-
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * $degree) ;-
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn(-$dir * $degree) ;-
    Peano($length / $dist_rel, $split - 1, 1) ;F
    Turn($dir * $degree) ;+
    Peano($length / $dist_rel, $split - 1, 1) ;F
    EndIf
    ;Sleep(0)
    EndFunc

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

    Func Turn ($degrees)
    $angle = $angle + ($degrees * $Pi_Div_180)
    EndFunc

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

    Func Draw_and_Forward($length)
    $x2 = $x1 + Cos($angle) * $length
    $y2 = $y1 + Sin($angle) * $length
    ;~ Local $red = ((Cos(1 * $x1 / 64) + 1) / 2) * 256
    ;~ Local $green = ((Cos(1.25 * $y2 / 64) + 1) / 2) * 256
    ;~ Local $blue = ((Cos(1.5 * $x2 / 64) + 1) / 2) * 256
    ;~ _GDIPlus_PenSetColor($Pen, "0xEF" & Hex($red, 2) & Hex($green, 2) & Hex($blue, 2)) ;Set the pen color
    _GDIPlus_PenSetColor($Pen, "0x68000000") ;Set the pen color
    _GDIPlus_GraphicsDrawLine($hGraphic, $x1, $y1, $x2, $y2, $Pen)
    $x1 = $x2
    $y1 = $y2
    EndFunc

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

    Func Forward_Only($length)
    $x2 = $x1 + Cos($angle) * $length
    $y2 = $y1 + Sin($angle) * $length
    $x1 = $x2
    $y1 = $y2
    EndFunc

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

    Func Draw_Text()
    Local $Text_Layout2
    Local $text_info = "UEZ 2009 ;-)"
    $Text_Layout = _GDIPlus_RectFCreate (0, $height - 1.75 * $font_size, 0, 0)
    $Text_Layout2 = _GDIPlus_RectFCreate ($width - StringLen($text_info) * $font_size * 0.67, $height - 1.75 * $font_size, 0, 0)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, $text, $Font, $Text_Layout, $String_Format, $Brush)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, $text_info, $Font, $Text_Layout2, $String_Format, $Brush)
    EndFunc

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

    Func Save_PIC()
    If _IsPressed("78", $dll) Then
    _GDIPlus_Save_to_Image(@ScriptDir & "\L-SF-Screenshot_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC, $hGUI)
    If @error Then MsgBox(16, "ERROR", "Image was not saved!", 10)
    EndIf
    EndFunc

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

    ; #FUNCTION# =============================================================================
    ; Name.............: _GDIPlus_Save_to_Image
    ; Description ...: INTERNAL FUNCTION - save drawn elements in GUI to file
    ; Syntax...........: _GDIPlus_Save_to_Image($file, $hWnd)
    ; Parameters ...: $file - filename
    ; $hWnd - handle to GUI
    ; Author .........: ptrex, ProgAndy, UEZ
    ; =========================================================================================
    Func _GDIPlus_Save_to_Image($file, $hWnd)
    Local $hDC, $memBmp, $memDC, $hImage, $w, $h, $size, $err, $sCLSID, $ext, $fExt
    If $file <> "" Or $hWnd <> "" Then
    $size = WinGetClientSize($hWnd)
    $w = $size[0]
    $h = $size[1]
    $hDC = _WinAPI_GetDC($hWnd)
    $memDC = _WinAPI_CreateCompatibleDC($hDC)
    $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
    _WinAPI_SelectObject ($memDC, $memBmp)
    _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ; 0x00CC0020 = $SRCCOPY
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
    $ext = "png,bmp,jpg,tif,gif"
    $fExt = StringRight($file, 3)
    If Not StringInStr($ext, $fExt) Then
    $CLSID = "PNG"
    $file &= ".png"
    Else
    $CLSID = $fExt
    EndIf
    $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID)
    If Not _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID) Then $err = 1
    _GDIPlus_ImageDispose ($hImage)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($memDC)
    _WinAPI_DeleteObject ($memBmp)
    If $err Then Return SetError(2, 0, 0)
    Return SetError(0, 0, 0)
    Else
    Return SetError(1, 0, 0)
    EndIf
    EndFunc

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

    Func _Exit()
    AdlibUnRegister("Save_PIC")
    ; Clean up resources
    _GDIPlus_PenDispose($Pen)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_FontDispose ($Font)
    _GDIPlus_FontFamilyDispose ($Font_Family)
    _GDIPlus_StringFormatDispose ($String_Format)
    _GDIPlus_BrushDispose($Brush)
    _GDIPlus_Shutdown ()
    DllClose($dll)
    Exit
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Geniale Sache UEZ ! Bei mir läuft alles bestens und sauber :).

    Falls jemand daran interessiert ist hier noch meine JAR-Datei des Sierpinski-Dreiecks.