#include <GUIConstantsEx.au3>
#include <ColorConstantS.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>


#Region ### Variablen ###
;~ Fensterattribute
$Width = 1
$WinWidth = @DesktopWidth
$WinHeight = @DesktopHeight
$ZenWidth = $WinWidth / 2
$ZenHeight = $WinHeight / 2

;~ Kreis Gross attribute
$kg_radius = $ZenHeight
$kg_winkel = 0
$kg_richtung = 1
$kg_schritt = 1

;~ Kreis Klein attribute
$kk_radius = $kg_radius / 2
$kk_winkel = 0
$kk_richtung = 1
$kk_schritt = 2

;~ Allgemeine Variablen
$generate = 0
$PI = 3.141592653589793
$r = "00"
$g = "00"
$b = "00"
$color = "0xFF" & $r & $g & $b
#EndRegion ### Variablen ###


#Region ### GUI ###
$RandomWindow = GUICreate("Randomwindow", @DesktopWidth, @DesktopHeight, 0, 0,-2147483648)
GUISetBkColor($COLOR_WHITE)
$b_start = GUICtrlCreateButton("GENERATE", 10, 10, 200, 100)
GUICtrlSetFont($b_start, 25)
$b_refresh = GUICtrlCreateButton("REFRESH", $WinWidth - 210, 10, 200, 100)
GUICtrlSetFont($b_refresh, 25)
GUICtrlCreateLabel("Outer step", 10, 120, 250, 50)
GUICtrlSetFont(-1, 25)
$i_schritt_g = GUICtrlCreateInput($kg_schritt, 10, 170, 200, 50)
GUICtrlSetFont($i_schritt_g, 25)
GUICtrlCreateLabel("Inner step", 10, 230, 250, 50)
GUICtrlSetFont(-1, 25)
$i_schritt_k = GUICtrlCreateInput($kk_schritt, 10, 280, 200, 50)
GUICtrlSetFont($i_schritt_k, 25)
GUICtrlCreateLabel("Speed", 10, 340, 250, 50)
GUICtrlSetFont(-1, 25)
$slider_speed = GUICtrlCreateSlider(10, 390, 200, 30)
GUICtrlSetFont(-1, 25)
GUICtrlSetLimit(-1, 250)
GUICtrlSetData(-1, 250)
$checkbox = GUICtrlCreateCheckbox("Beginn from start", 10, 450, 200, 30)
GUICtrlSetFont(-1, 15)
GUICtrlCreateLabel("COLOR", 90, $WinHeight - 250, 120, 35)
GUICtrlSetFont(-1, 25)
$slider_red = GUICtrlCreateSlider(50, $WinHeight - 200, 200, 30)
GUICtrlSetLimit(-1, 255)
GUICtrlCreateLabel("R", 20, $WinHeight - 200, 30, 30)
GUICtrlSetFont(-1, 20)
$slider_green = GUICtrlCreateSlider(50, $WinHeight - 150, 200, 30)
GUICtrlSetLimit(-1, 255)
GUICtrlCreateLabel("G", 20, $WinHeight - 150, 30, 30)
GUICtrlSetFont(-1, 20)
$slider_blue = GUICtrlCreateSlider(50, $WinHeight - 100, 200, 30)
GUICtrlSetLimit(-1, 255)
GUICtrlCreateLabel("B", 20, $WinHeight - 100, 30, 30)
GUICtrlSetFont(-1, 20)
GUISetState(@SW_SHOW)
#EndRegion ### GUI ###


#Region ### GDI ###
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($RandomWindow)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($WinWidth,$WinHeight,$hGraphic)
$hBrush = _GDIPlus_BrushCreateSolid (0xFFFFFFFF)
$hRect = _GDIPlus_BrushCreateSolid(0xFF000000)
_GDIPlus_GraphicsFillRect($hGraphic, 270, $WinHeight - 200, 50, 130, $hRect)
#EndRegion ### GDI ###


#Region ### Schlaufe ###
GUIRegisterMsg($WM_HSCROLL, "_Pen")
While 1
   $hPen = _GDIPlus_PenCreate($color, 1)
   $nMsg = GUIGetMsg()
   Switch $nMsg
	  Case $GUI_EVENT_CLOSE
		 _Exit()
	  Case $b_start
		 _Do()
	  Case $b_refresh
		 _GDIPlus_GraphicsFillRect($hGraphic, $ZenWidth - $ZenHeight, 0, 2*$ZenHeight, $WinHeight, $hBrush)
		 $kg_winkel = 0
		 $kk_winkel = 0
		 _Do(1)
	  Case $slider_red
		 _Pen()
	  Case $slider_green
		 _Pen()
	  Case $slider_blue
		 _Pen()
	  EndSwitch
   If $generate = 1 Then
	  _Draw()
	  Sleep(250-GUICtrlRead($slider_speed))
   EndIf
WEnd
#EndRegion ### Schlaufe ###


#Region ### Funktionen ###
Func _Do($var = 0)
   If $generate = 0 And $var = 0 Then
	  $generate = 1
	  GUICtrlSetData($b_start, "STOP")
	  GUICtrlSetState($i_schritt_g, $GUI_DISABLE)
	  GUICtrlSetState($i_schritt_k, $GUI_DISABLE)
	  $kg_schritt = GUICtrlRead($i_schritt_g)
	  $kk_schritt = GUICtrlRead($i_schritt_k)
	  If _IsChecked($checkbox) Then
		 $kg_winkel = 0
		 $kk_winkel = 0
	  EndIf
   Else
	  $generate = 0
	  GUICtrlSetData($b_start, "GENERATE")
	  GUICtrlSetState($i_schritt_g, $GUI_ENABLE)
	  GUICtrlSetState($i_schritt_k, $GUI_ENABLE)
   EndIf
EndFunc

Func _Pen()
   $r = StringTrimLeft(Hex(GUICtrlRead($slider_red)),6)
   $g = StringTrimLeft(Hex(GUICtrlRead($slider_green)),6)
   $b = StringTrimLeft(Hex(GUICtrlRead($slider_blue)),6)
   $color = "0xFF" & $r & $g & $b
   $hRect = _GDIPlus_BrushCreateSolid($color)
   _GDIPlus_GraphicsFillRect($hGraphic, 270, $WinHeight - 200, 50, 130, $hRect)
EndFunc

Func _Draw()
   $xg = $ZenWidth + (Cos(($PI*$kg_winkel)/180) * $kg_radius)
   $yg = $ZenHeight + (Sin(($PI*$kg_winkel)/180) * $kg_radius)
   $xk = $ZenWidth + (Cos(($PI*$kk_winkel)/180) * $kk_radius)
   $yk = $ZenHeight + (Sin(($PI*$kk_winkel)/180) * $kk_radius)
   _GDIPlus_GraphicsDrawLine($hGraphic, $xg, $yg, $xk, $yk, $hPen)
   $kg_winkel += $kg_schritt
   If $kg_winkel >= 360 Then
	  $kg_winkel -= 360
   EndIf
   $kk_winkel += $kk_schritt
   If $kk_winkel >= 360 Then
	  $kk_winkel -= 360
   EndIf
EndFunc

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func _Exit()
   _GDIPlus_BrushDispose ($hBrush)
   _GDIPlus_PenDispose($hPen)
   _GDIPlus_GraphicsDispose ($hGraphic)
   _GDIPlus_Shutdown ()
   Exit
EndFunc
#EndRegion ### Funktionen ###

;~ 1 122
;~ 0.5  61
;~ 0.25 30.5
;~ 0.25 60.5

;~ 0.5 10

