#Region ### START Includes ###
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#EndRegion ### END Global Includes ###


#Region ### START Global Declarations ###
Global $wWidth = @DesktopWidth / 4
Global $wHeight = $wWidth
Global $mWidth = @DesktopWidth / 8
Global $mHeight = $mWidth
Global $pi = 3.1415926535898
Global $Anz = 2
Global $sit = 0
Global $factor = 0.9
Global $decr = 0.9999
#EndRegion ### END Global Declarations ###


#Region ### START Curve settings ###
Global $px[$Anz], $py[$Anz], $step_x[$Anz], $step_y[$Anz], $sit_x[$Anz], $sit_y[$Anz]
;~ Curve settings
$px[0] = $mWidth + ($mHeight/2)
$py[0] = $mHeight
$step_x[0] = (2*$pi) / 60
$step_y[0] = (2*$pi) / 90
$sit_x[0] = 0
$sit_y[0] = 0
#EndRegion ### END Circle options ###


#Region ### START Gui ###
$hGui = GUICreate("Draw something", $wWidth, $wHeight)
GUISetState(@SW_SHOW)
#EndRegion ### END Gui ###


#Region ### START GDI+ ###
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($wWidth, $wHeight, $hGraphic)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hPen = _GDIPlus_PenCreate(0xFF0000FF)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4)
#EndRegion ### END GDI+ ###


#Region ### START Process ###
While 1
;~    _GDIPlus_GraphicsClear($hBuffer, 0x00FFFFFF)
   $nMsg = GUIGetMsg()
   Switch $nMsg
   Case $GUI_EVENT_CLOSE
	  _Exit()
   EndSwitch
   _Calc()
   _Draw_Lines()
;~    _GDIPlus_GraphicsDrawImageRect($hGraphic,$hBitmap,0,0, $wWidth, $wHeight)
WEnd
#EndRegion ### END Process ###


#Region ### START Functions ###
Func _Calc()
   $px[1] = $px[0]
   $py[1] = $py[0]
   $sit_x[0] += $step_x[0]
   $sit_y[0] += $step_y[0]
   $px[0] = $mWidth + $mWidth*$factor * cos($sit_x[0])
   $py[0] = $mHeight - $mHeight*$factor * sin($sit_y[0])
   $factor -= (1-$decr)
   If $factor <= 0 Then
	  msgbox(0,"","Finish")
	  _Exit()
   EndIf
;~    Cut first line
   If $sit = 0 Then
	  $px[1] = $px[0]
	  $py[1] = $py[0]
	  $sit += 1
   EndIf
EndFunc

Func _Draw_Lines()
   _GDIPlus_GraphicsDrawLine($hGraphic, $px[0], $py[0], $px[1], $py[1], $hPen)
EndFunc

Func _Exit()
   _GDIPlus_GraphicsDispose($hGraphic)
   _GDIPlus_Shutdown()
   Exit
EndFunc
#EndRegion ### END Functions ###