#Region Includes
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Color.au3>
#include <GDIPlus.au3>
#EndRegion


#Region Declarations
;~ Window
Global $wWidth = @DesktopWidth
Global $wHeight = @DesktopHeight
Global $mWidth = $wWidth *0.47
Global $mHeight = $mWidth *0.55
Global $mPosX0 = $wWidth / 2
Global $mPosY0 = $wHeight / 2
;~ Ellipse
Local $p = 40
Local $ps = $p / 10
Global $scale = 0.05
Local $hBrush_col[3]
$hBrush_col[0] = 0xFF
$hBrush_col[1] = 0x56
$hBrush_col[2] = 0xBB
#EndRegion


#Region Position attributes
Global $pi = 3.1415926535898
Global $Anz = InputBox("Anzahl festlegen", "Anzahl Kreise? (zwischen 1 und 100 eingeben)")
Global $aPoints[$Anz+1][$Anz-1]
Global $Radius = 0.25
Global $Radius_x = 0
Global $Radius_y = 0
Global $px[$Anz], $py[$Anz], $step_x[$Anz], $step_y[$Anz], $sit_x[$Anz], $sit_y[$Anz], $sit_step = 0
For $i = 0 To $Anz - 1
   $px[$i] = $mWidth + ($mHeight/2)
   $py[$i] = $mHeight
   $step_x[$i] = (2*$pi) / 90
   $step_y[$i] = (2*$pi) / 90
   $sit_x[$i] = $sit_step
   $sit_y[$i] = $sit_step
   $sit_step += (2*$pi) * (1/$Anz)
Next
#EndRegion


#Region HotKeySet
HotKeySet("{UP}", "_radius_up")
HotKeySet("{DOWN}", "_radius_down")
#EndRegion


#Region Gui
$hGui = GUICreate("Form1", $wWidth, $wHeight, 0, 0,-2147483648)
GUISetBkColor(0x000000, $hGUI)
GUISetState(@SW_SHOW)
#EndRegion


#Region GDI+
;~ init
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($wWidth, $wHeight, $hGraphics)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

;~ sustigs
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 4)
$hBrush = _GDIPlus_BrushCreateSolid()
$hPen = _GDIPlus_PenCreate(0xA0000000, 2)

;~ verblassen
$hBuffer = _GDIPlus_BitmapCreateFromScan0($wWidth, $wHeight)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBuffer)
_GDIPlus_GraphicsTranslateTransform($hContext, -($wWidth/2) * $scale, -($wHeight/2) * $scale)
_GDIPlus_GraphicsScaleTransform($hContext, 1 + $scale, 1 + $scale)
_GDIPlus_GraphicsSetInterpolationMode($hContext, 1)
#EndRegion


#Region Loop
GUIRegisterMsg($WM_MOUSEWHEEL, "_WM_MOUSEWHEEL")
MouseMove($mPosX0,$mPosY0)
While 1
   _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hBuffer, 0, 0, $wWidth, $wHeight)

   $nMsg = GUIGetMsg()
   Switch $nMsg
	  Case $GUI_EVENT_CLOSE
		 _Exit()
   EndSwitch
   _CheckMouse()
   _Calc()
   _Draw()
   _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $wWidth, $wHeight)
   _GDIPlus_GraphicsDrawImageRect($hContext, $hBitmap, 0, 0, $wWidth, $wHeight)
WEnd
#EndRegion


#Region Functions
Func _CheckMouse()
   $mPos = MouseGetPos()
   $Radius = ($mPos[0] / $wWidth) * 0.6 + 0.025
   $p = ($mPos[1] / $wHeight) * 100 + 10
EndFunc


Func _Calc()
   For $i = 0 To ($Anz-1)
	  $sit_x[$i] += $step_x[$i]
	  $sit_y[$i] += $step_y[$i]
	  $px[$i] = $mWidth + $mWidth*$Radius * cos($sit_x[$i]) + $Radius_x
	  $py[$i] = $mHeight - $mHeight*$Radius * sin($sit_y[$i]) + $Radius_y
   Next
EndFunc


Func _radius_up()
   $Radius_x += @DesktopWidth/100
   $Radius_y += @DesktopHeight/100
EndFunc


Func _radius_down()
   $Radius_x -= @DesktopWidth/100
   $Radius_y -= @DesktopHeight/100
EndFunc


Func _Draw()
;~    SetColor
   For $i = 0 To 2
	  If $hBrush_col[$i] > 0x00 Then
		 $hBrush_col[$i] -= Random(0, 0x05, 1)
	  Else
		 $hBrush_col[$i] = 0xFF
	  EndIf
   Next
;~    $hBrush_col[0] = 0xFF - Random(0, 0x00, 1)
;~    $hBrush_col[1] = 0xFF - Random(0, 0x00, 1)
;~    $hBrush_col[2] = 0xFF - Random(0, 0x00, 1)
   _GDIPlus_BrushSetSolidColor($hBrush, "0x70" & Hex(_ColorSetRGB($hBrush_col), 6))
   _GDIPlus_PenSetWidth($hPen, $ps)
;~    Draw Ellipse or Rectangle
   For $i = 0 To ($Anz-1)
	  _GDIPlus_GraphicsDrawEllipse($hBackBuffer, $px[$i], $py[$i], $p, $p, $hPen)
	  _GDIPlus_GraphicsFillEllipse($hBackBuffer, $px[$i], $py[$i], $p, $p, $hBrush)
;~ 	  _GDIPlus_GraphicsDrawRect($hBackBuffer, $px[$i], $py[$i], 50, 50, $hPen)
;~ 	  _GDIPlus_GraphicsFillRect($hBackBuffer, $px[$i], $py[$i], 50, 50, $hBrush)
   Next
EndFunc


Func _WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
   If $wParam = 0x00780000 Then
	  $scale = 0.025
   ElseIf $wParam = 0xFF880000 Then
	  $scale = -0.025
   EndIf
   _GDIPlus_GraphicsTranslateTransform($hContext, -($wWidth/2) * $scale, -($wHeight/2) * $scale)
   _GDIPlus_GraphicsScaleTransform($hContext, 1 + $scale, 1 + $scale)
   Return $GUI_RUNDEFMSG
EndFunc


Func _Exit()
   _GDIPlus_GraphicsDispose($hGraphics)
   _GDIPlus_BrushDispose ($hBrush)
   _GDIPlus_PenDispose($hPen)
   _GDIPlus_Shutdown()
   Exit
EndFunc
#EndRegion


