#include <GDIP.au3>

$iWidth = 1000
$iHeight = 1000
$iDistance = 50
$iIterations = 13 ;Bitte vorsichtig erhöhen, da ALLE Koordinaten des Fraktals zum selben Zeitpunkt im Speicher sind.

$hWnd = GUICreate("GDI+ Dragon-Curve | Iterations: " & $iIterations, $iWidth, $iHeight)
GUISetState()

_GDIPlus_Startup()

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
_GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)

$hPen = _GDIPlus_PenCreate(0xFF000000, 1)
$hPath = _GDIPlus_PathCreate()

_GDIPlus_PathAddLine($hPath, 1, 0, 0, 0)
_GDIPlus_PathAddLine($hPath, 0, 0, 0, 1)
_GDIPlus_PathAddLine($hPath, 0, 1, 1, 1)
_GDIPlus_PathAddLine($hPath, 1, 1, 1, 2)

For $iI = 1 To $iIterations
	$aPoint = _GDIPlus_PathGetLastPoint($hPath)
	$hPathBuffer = _GDIPlus_PathClone($hPath)

	$hMatrix_R = _GDIPlus_MatrixCreate()
	_GDIPlus_MatrixTranslate($hMatrix_R, $aPoint[0], $aPoint[1])
	_GDIPlus_MatrixRotate($hMatrix_R, 90)
	_GDIPlus_MatrixTranslate($hMatrix_R, -$aPoint[0], -$aPoint[1])

	_GDIPlus_PathTransform($hPathBuffer, $hMatrix_R)
	_GDIPlus_PathReverse($hPathBuffer)
	_GDIPlus_PathAddPath($hPath, $hPathBuffer, False)

	_GDIPlus_PathDispose($hPathBuffer)
	_GDIPlus_MatrixDispose($hMatrix_R)
Next

Do
	$aBounds = _GDIPlus_PathGetWorldBounds($hPath, 0, $hPen)
	If $aBounds[2] > $aBounds[3] Then
		$nScale = ($iWidth - $iDistance * 2) / $aBounds[2]
	Else
		$nScale = ($iHeight - $iDistance * 2) / $aBounds[3]
	EndIf

	$hMatrix = _GDIPlus_MatrixCreate()
	_GDIPlus_MatrixScale($hMatrix, $nScale, $nScale)
	_GDIPlus_PathTransform($hPath, $hMatrix)
	_GDIPlus_MatrixDispose($hMatrix)

	$aBounds = _GDIPlus_PathGetWorldBounds($hPath, 0, $hPen)
Until Abs(($iWidth - $iDistance * 2) - $aBounds[2]) <= 10 Or Abs(($iHeight - $iDistance * 2) - $aBounds[3]) <= 10

$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, -$aBounds[0] + $iWidth / 2 - $aBounds[2] / 2, -$aBounds[1] + $iHeight / 2 - $aBounds[3] / 2)
_GDIPlus_PathTransform($hPath, $hMatrix)
_GDIPlus_MatrixDispose($hMatrix)

_GDIPlus_GraphicsDrawPath($hBuffer, $hPath, $hPen)
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight)

_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_PenDispose($hPen)
_GDIPlus_PathDispose($hPath)
_GDIPlus_Shutdown()

While GUIGetMsg() <> -3
WEnd
