#include <GDIPlus.au3>

Global Const $iRadius = 383 / 2, $pi = ATan(1) * 4

_GDIPlus_Startup()

$hGUI = GUICreate("Times Table", 626, 458, 192, 124)

GUICtrlCreateLabel("Multiplier", 464, 16, 90, 26)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")

$hMultiplier = GUICtrlCreateInput("2", 472, 40, 121, 30, 1)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
GUICtrlCreateUpdown(-1)

GUICtrlCreateLabel("Segments", 464, 88, 97, 26)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")

$hSegments = GUICtrlCreateInput("20", 472, 112, 121, 30, 1)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
GUICtrlCreateUpdown(-1)

$hCalculate = GUICtrlCreateButton("Calculate", 464, 408, 147, 41)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
GUISetState(@SW_SHOW)

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hWhiteBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
_DrawTable(2, 20)

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case -3
			_GDIPlus_GraphicsDispose($hGraphics)
			_GDIPlus_Shutdown()
			Exit

		Case $hCalculate
			_DrawTable(GUICtrlRead($hMultiplier), GUICtrlRead($hSegments))

	EndSwitch
WEnd

Func _ClearScreen()
	_GDIPlus_GraphicsFillRect($hGraphics, 8, 8, 443, 443, $hWhiteBrush)
	_GDIPlus_GraphicsDrawRect($hGraphics, 8, 8, 442, 442)
EndFunc

Func _DrawTable($iMultiplier, $iSegments)
	_ClearScreen()
	_GDIPlus_GraphicsDrawEllipse($hGraphics, 38, 38, 383, 383)

	Local $aSegments[$iSegments][2]
	For $i = 0 To $iSegments - 1
		$angle = $i / $iSegments * 360
		$a1 = $angle
		$mul_x = 1
		$mul_y = 1

		If $angle <= 90 Then
			$angle = 90 - $angle
			$mul_x = 1
			$mul_y = 1
		ElseIf $angle > 90 and $angle <= 180 Then
			$angle = $angle - 90
			$mul_x = 1
			$mul_y = -1
		ElseIf $angle > 180 and $angle <= 270 Then
			$angle = 270 - $angle
			$mul_x = -1
			$mul_y = -1
		ElseIf $angle > 270  and $angle < 360 Then
			$angle = $angle - 270
			$mul_x = -1
			$mul_y = 1
		EndIf

		$x = $mul_x * $iRadius * cos($angle * ($pi / 180)) + 38 + 383 / 2
		$y = $mul_y * $iRadius * sin($angle * ($pi / 180)) + 38 + 383 / 2
		_GDIPlus_GraphicsFillRect($hGraphics, $x - 2, $y - 2, 4, 4)

		$aSegments[$i][0] = $x
		$aSegments[$i][1] = $y
	Next

	For $i = 0 To $iSegments - 1
		_GDIPlus_GraphicsDrawLine($hGraphics, $aSegments[$i][0], $aSegments[$i][1], $aSegments[Mod($iMultiplier * $i, $iSegments)][0], $aSegments[Mod($iMultiplier * $i, $iSegments)][1])
	Next
EndFunc