#include <GDIP.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $aKeyBuffer[4] = [0, 0, 0, 0], $iKey

Global $aBrush[8] = [0xFF0080FF, 0xFF0000FF, 0xFF8000FF, 0xFFFF0000, 0xFFFF8000, 0xFF80FF00, 0xFF00FF00, 0xFF00FF80]

;Global Const $cBlock_F[5][5][5] = [[[0, 0, 0, 0, 0],[4, 2, 0, 0, 0],[4, 2, 0, 0, 0],[4, 2, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True]],[[0, 0, 0, 0, 0],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True]],[[0, 0, 0, 0, 0],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True]],[[0, 0, 0, 0, 0],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True],[0, True, True, True, True]]]

Global Const $cBlock_1[5][5][5] = [[[0, 0, 0, 0, 0],[1, 0, 0, 0, 0],[1, 0, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_2[5][5][5] = [[[0, 0, 0, 0, 0],[3, 1, 0, 0, 0],[2, 1, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_3[5][5][5] = [[[0, 0, 0, 0, 0],[3, 1, 0, 0, 0],[2, 1, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_4[5][5][5] = [[[0, 0, 0, 0, 0],[4, 2, 0, 0, 0],[1, 0, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_5[5][5][5] = [[[0, 0, 0, 0, 0],[3, 1, 0, 0, 0],[2, 1, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_6[5][5][5] = [[[0, 0, 0, 0, 0],[2, 1, 0, 0, 0],[2, 1, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_7[5][5][5] = [[[0, 0, 0, 0, 0],[2, 1, 0, 0, 0],[1, 0, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_8[5][5][5] = [[[0, 0, 0, 0, 0],[2, 1, 0, 0, 0],[2, 1, 0, 0, 0],[1, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]

Global Const $cBlock_9[5][5][5] = [[[0, 0, 0, 0, 0],[2, 1, 0, 0, 0],[2, 1, 0, 0, 0],[2, 1, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, True, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, True, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]
Global Const $cBlock_10[5][5][5] = [[[0, 0, 0, 0, 0],[2, 1, 0, 0, 0],[2, 1, 0, 0, 0],[2, 1, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, True, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, True, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]],[[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0]]]

Global $aBlocks[11]
$aBlocks[0] = UBound($aBlocks) - 1
For $i = 1 To $aBlocks[0]
	$aBlocks[$i] = Eval("cBlock_" & $i)
Next

HotKeySet("{ESC}", "_Exit")

Opt("GUIOnEventMode", 1)

Global $iWidth = @DesktopWidth
Global $iHeight = @DesktopHeight * 0.9
$iWidth = $iHeight * 4 / 3
Global $nPerspective = 0.3
Global $aCnt[3] = [5, 5, 12]

Global $iXPos
Global $iYPos
Global $iZPos
Global $aBlock
Global $aField[$aCnt[0]][$aCnt[1]][$aCnt[2]]

_GDIPlus_Startup()

For $i = 0 To 7
	$aBrush[$i] = _GDIPlus_BrushCreateSolid($aBrush[$i])
Next

Global $aPathX = _CreatePathX($iWidth, $iHeight, $aCnt, $nPerspective)
Global $aPathY = _CreatePathY($iWidth, $iHeight, $aCnt, $nPerspective)
Global $aPathZ = _CreatePathZ($aPathX, $aCnt)
Global $hPathGrid = _CreatePathGrid($aPathX, $aPathY, $aPathZ, $aCnt)

Global $hGui = GUICreate("Test", $iWidth, $iHeight);, 0, 0, $WS_POPUP)
GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")

Global $LeftID = GUICtrlCreateButton("", 0, -90)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $RightID = GUICtrlCreateButton("", 0, -70)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $DownID = GUICtrlCreateButton("", 0, -50)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $UpID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $ForID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $BackID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)

Global $RotXFID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $RotXBID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)

Global $RotYFID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $RotYBID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)

Global $RotZFID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)
Global $RotZBID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)

Global $DropID = GUICtrlCreateButton("", 0, -30)
GUICtrlSetOnEvent(-1, "_SetKey")
GUICtrlSetState(-1, $GUI_HIDE)

Global $AccelKeys[13][2] = [["{Space}", $DropID],["{Left}", $LeftID],["{Right}", $RightID],["{Down}", $DownID],["{Up}", $UpID],["{Enter}", $ForID],["{Bs}", $BackID],["q", $RotXFID],["a", $RotXBID],["s", $RotYFID],["w", $RotYBID],["d", $RotZFID],["e", $RotZBID]]
GUISetAccelerators($AccelKeys)


Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)
Global $hBmpGrid = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
Global $hGfxGrid = _GDIPlus_ImageGetGraphicsContext($hBmpGrid)
_GDIPlus_GraphicsSetSmoothingMode($hGfxGrid, 2)
Global $hBmpBackGround = _CreateBackGround($hGraphics, $iWidth, $iHeight, $nPerspective)

_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)

Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
Global $hPen = _GDIPlus_PenCreate(0xFF000000)
Global $hPenGrid = _GDIPlus_PenCreate(0xFF009900)

Global $hPenBlock = _GDIPlus_PenCreate(0xFFFFFFFF, 3)
_GDIPlus_PenSetLineJoin($hPenBlock, 1)


GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState()

_GDIPlus_GraphicsDrawImage($hGfxGrid, $hBmpBackGround, 0, 0)
_GDIPlus_GraphicsDrawPath($hGfxGrid, $hPathGrid, $hPenGrid)
_DrawField($hGfxGrid, $aField, $aPathX, $aPathY, $aPathZ, $aCnt, $aBrush, $hPen)
_NewBlock()

While 1
	$iKey = _GetKey($aKeyBuffer)
	Switch $iKey
		Case $UpID, $DownID, $LeftID, $RightID, $ForID, $BackID
			_Move($iKey)
		Case $RotXFID, $RotXBID, $RotYFID, $RotYBID, $RotZFID, $RotZBID
			_Rotate($iKey)
		Case $DropID
			_Drop($aBlock, $aField)
		Case Else
			_CheckFullField($aField)
			_GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpGrid, 0, 0)
			_DrawBlockRotate($hGfxBuffer, $aBlock, $iXPos, $iYPos, $iZPos, 0, 0, 0, $aPathX, $aPathY, $aPathZ, $hPenBlock)
			_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
	EndSwitch
	Sleep(10)
WEnd

Func _CheckFullField(ByRef $aField)
	Local $bFull
	For $z = $aCnt[2] - 1 To 1 Step -1
		$bFull = True
		For $x = 0 To $aCnt[0] - 1
			For $y = 0 To $aCnt[1] - 1
				If Not $aField[$x][$y][$z] Then
					$bFull = False
					ExitLoop 2
				EndIf
			Next
		Next
		If $bFull Then
			For $z1 = $z To 1 Step -1
				For $x = 0 To $aCnt[0] - 1
					For $y = 0 To $aCnt[1] - 1
						$aField[$x][$y][$z1] = $aField[$x][$y][$z1 - 1]
					Next
				Next
			Next
			_GDIPlus_GraphicsDrawImage($hGfxGrid, $hBmpBackGround, 0, 0)
			_GDIPlus_GraphicsDrawPath($hGfxGrid, $hPathGrid, $hPenGrid)
			_DrawField($hGfxGrid, $aField, $aPathX, $aPathY, $aPathZ, $aCnt, $aBrush, $hPen)
			$z -= 1
		EndIf
	Next
EndFunc   ;==>_CheckFullField


Func _NewBlock()
	$aBlock = $aBlocks[Random(1, $aBlocks[0], 1)]
	$iXPos = Floor($aCnt[0] / 2 - $aBlock[0][1][0] / 2)
	$iYPos = Floor($aCnt[1] / 2 - $aBlock[0][2][0] / 2)
	$iZPos = 0
EndFunc   ;==>_NewBlock


Func _Drop($aBlock, ByRef $aField)
	While 1
		For $iBX = 0 To $aBlock[0][1][0] - 1
			For $iBY = 0 To $aBlock[0][2][0] - 1
				For $iBZ = 0 To $aBlock[0][3][0] - 1
					If $aBlock[$iBX + 1][$iBY + 1][$iBZ + 1] Then
						If $iBZ + $iZPos < 0 Then ContinueLoop
						If $iBZ + $iZPos + 1 >= $aCnt[2] Or $aField[$iXPos + $iBX][$iYPos + $iBY][$iZPos + $iBZ + 1] Then
							_BlockToField($aField, $aBlock)
							Return
						EndIf
					EndIf
				Next
			Next
		Next
		$iZPos += 1
	WEnd
EndFunc   ;==>_Drop

Func _BlockToField(ByRef $aField, $aBlock)
	For $iBX = 0 To $aBlock[0][1][0] - 1
		For $iBY = 0 To $aBlock[0][2][0] - 1
			For $iBZ = 0 To $aBlock[0][3][0] - 1
				If $aBlock[$iBX + 1][$iBY + 1][$iBZ + 1] Then $aField[$iXPos + $iBX][$iYPos + $iBY][$iZPos + $iBZ] = True
			Next
		Next
	Next
	_GDIPlus_GraphicsDrawImage($hGfxGrid, $hBmpBackGround, 0, 0)
	_GDIPlus_GraphicsDrawPath($hGfxGrid, $hPathGrid, $hPenGrid)
	_DrawField($hGfxGrid, $aField, $aPathX, $aPathY, $aPathZ, $aCnt, $aBrush, $hPen)
	_NewBlock()
EndFunc   ;==>_BlockToField




Func _GetKey(ByRef $aKeyBuffer)
	Local $iReturn = $aKeyBuffer[0]
	For $i = 0 To UBound($aKeyBuffer) - 2
		$aKeyBuffer[$i] = $aKeyBuffer[$i + 1]
	Next
	Return $iReturn
EndFunc   ;==>_GetKey

Func _Setkey()
	Local $iMax = UBound($aKeyBuffer) - 2
	If $aKeyBuffer[$iMax] Then Return
	For $i = 0 To $iMax
		If Not $aKeyBuffer[$i] Then
			$aKeyBuffer[$i] = @GUI_CtrlId
			Return
		EndIf
	Next
EndFunc   ;==>_Setkey

Func _Move($GUI_CtrlId)
	Switch $GUI_CtrlId
		Case $LeftID
			$iXPos -= 1
			If $iXPos < 0 Then $iXPos = 0
		Case $RightID
			$iXPos += 1
			If $iXPos > $aCnt[0] - $aBlock[0][1][0] Then $iXPos = $aCnt[0] - $aBlock[0][1][0]
		Case $UpID
			$iYPos -= 1
			If $iYPos < 0 Then $iYPos = 0
		Case $DownID
			$iYPos += 1
			If $iYPos > $aCnt[1] - $aBlock[0][2][0] Then $iYPos = $aCnt[1] - $aBlock[0][2][0]
		Case $ForID
			$iZPos -= 1
			If $iZPos < 0 Then $iZPos = 0
		Case $BackID
			$iZPos += 1
			If $iZPos > $aCnt[2] - $aBlock[0][3][0] Then $iZPos = $aCnt[2] - $aBlock[0][3][0]
	EndSwitch
EndFunc   ;==>_Move


Func _Rotate($GUI_CtrlId)
	Local $aTemp = $aBlock, $iX = $iXPos, $iY = $iYPos, $iZ = $iZPos
	Switch $GUI_CtrlId
		Case $RotXFID
			_RotateBlock($aTemp, 1, 0, 0, $iX, $iY, $iZ)
		Case $RotXBID
			For $i = 1 To 3
				_RotateBlock($aTemp, 1, 0, 0, $iX, $iY, $iZ)
			Next
		Case $RotYFID
			_RotateBlock($aTemp, 0, 1, 0, $iX, $iY, $iZ)
		Case $RotYBID
			For $i = 1 To 3
				_RotateBlock($aTemp, 0, 1, 0, $iX, $iY, $iZ)
			Next
		Case $RotZFID
			_RotateBlock($aTemp, 0, 0, 1, $iX, $iY, $iZ)
		Case $RotZBID
			For $i = 1 To 3
				_RotateBlock($aTemp, 0, 0, 1, $iX, $iY, $iZ)
			Next
	EndSwitch
	If $iX >= 0 And $iY >= 0 And $iX <= $aCnt[0] - $aTemp[0][1][0] And $iY <= $aCnt[1] - $aTemp[0][2][0] And $iZ <= $aCnt[2] - $aTemp[0][3][0] Then
		For $i = 1 To 90 Step 9
			_GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpGrid, 0, 0)
			Switch $GUI_CtrlId
				Case $RotXBID, $RotYBID, $RotZBID
					$aBlock = $aTemp
					$iXPos = $iX
					$iYPos = $iY
					$iZPos = $iZ
			EndSwitch
			Switch $GUI_CtrlId
				Case $RotXFID
					_DrawBlockRotate($hGfxBuffer, $aBlock, $iXPos, $iYPos, $iZPos, $i, 0, 0, $aPathX, $aPathY, $aPathZ, $hPenBlock)
				Case $RotXBID
					_DrawBlockRotate($hGfxBuffer, $aBlock, $iXPos, $iYPos, $iZPos, 90 - $i, 0, 0, $aPathX, $aPathY, $aPathZ, $hPenBlock)
				Case $RotYFID
					_DrawBlockRotate($hGfxBuffer, $aBlock, $iXPos, $iYPos, $iZPos, 0, $i, 0, $aPathX, $aPathY, $aPathZ, $hPenBlock)
				Case $RotYBID
					_DrawBlockRotate($hGfxBuffer, $aBlock, $iXPos, $iYPos, $iZPos, 0, 90 - $i, 0, $aPathX, $aPathY, $aPathZ, $hPenBlock)
				Case $RotZFID
					_DrawBlockRotate($hGfxBuffer, $aBlock, $iXPos, $iYPos, $iZPos, 0, 0, $i, $aPathX, $aPathY, $aPathZ, $hPenBlock)
				Case $RotZBID
					_DrawBlockRotate($hGfxBuffer, $aBlock, $iXPos, $iYPos, $iZPos, 0, 0, 90 - $i, $aPathX, $aPathY, $aPathZ, $hPenBlock)
			EndSwitch
			_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
		Next
		$aBlock = $aTemp
		$iXPos = $iX
		$iYPos = $iY
		$iZPos = $iZ
	EndIf
EndFunc   ;==>_Rotate



Func _DrawBlockRotate($hGraphics, $aBlock, $iX, $iY, $iZ, $nAX, $nAY, $nAZ, $aPathX, $aPathY, $aPathZ, $hPen)
	Local $iIX = $aBlock[0][1][0]
	Local $iIY = $aBlock[0][2][0]
	Local $iIZ = $aBlock[0][3][0]
	Local $aData, $aVis
	For $z = $iIZ - 1 To 0 Step -1
		For $y = 0 To $iIY - 1
			For $x = 0 To $iIX - 1
				If $aBlock[$x + 1][$y + 1][$z + 1] Then
					;If $z + $iZ < 0 Then ContinueLoop
					$aVis = _GetVisible($aBlock, $x + 1, $y + 1, $z + 1)
					If @error Then ContinueLoop
					Select
						Case $nAX <> 0
							$aData = _DrawPathRectRotate($hGraphics, $nAX, $z, $y, $iZ, $iY, $aBlock[0][3][1], $aBlock[0][2][1], $aPathX[$x + $iX][1], $aPathX[$x + $iX][2], $aVis, 0)
							_DrawPathRectRotate($hGraphics, $nAX, $z, $y, $iZ, $iY, $aBlock[0][3][1], $aBlock[0][2][1], $aPathX[$x + $iX + 1][1], $aPathX[$x + $iX + 1][2], $aVis, $hPen, $aData, 0)
						Case $nAY <> 0
							$aData = _DrawPathRectRotate($hGraphics, $nAY, $z, $x, $iZ, $iX, $aBlock[0][3][1], $aBlock[0][1][1], $aPathY[$y + $iY][1], $aPathY[$y + $iY][2], $aVis, 0)
							_DrawPathRectRotate($hGraphics, $nAY, $z, $x, $iZ, $iX, $aBlock[0][3][1], $aBlock[0][1][1], $aPathY[$y + $iY + 1][1], $aPathY[$y + $iY + 1][2], $aVis, $hPen, $aData, 1)
						Case Else
							$aData = _DrawPathRectRotate($hGraphics, $nAZ, $x, $y, $iX, $iY, $aBlock[0][1][1], $aBlock[0][2][1], $aPathZ[$z + $iZ + 2][1], $aPathZ[$z + $iZ + 2][2], $aVis, 0)
							_DrawPathRectRotate($hGraphics, $nAZ, $x, $y, $iX, $iY, $aBlock[0][1][1], $aBlock[0][2][1], $aPathZ[$z + $iZ + 3][1], $aPathZ[$z + $iZ + 3][2], $aVis, $hPen, $aData, 2)
					EndSelect
				EndIf
			Next
		Next
	Next
EndFunc   ;==>_DrawBlockRotate

Func _GetVisible($aBlock, $iX, $iY, $iZ)
	Local $aReturn[6] = [True, True, True, True, True, True]
	Local $iCnt = 0
	If $iX > 1 And $aBlock[$iX - 1][$iY][$iZ] Then $aReturn[0] = False
	If $iX < 4 And $aBlock[$iX + 1][$iY][$iZ] Then $aReturn[1] = False
	If $iY > 1 And $aBlock[$iX][$iY - 1][$iZ] Then $aReturn[2] = False
	If $iY < 4 And $aBlock[$iX][$iY + 1][$iZ] Then $aReturn[3] = False
	If $iZ > 1 And $aBlock[$iX][$iY][$iZ - 1] Then $aReturn[4] = False
	If $iZ < 4 And $aBlock[$iX][$iY][$iZ + 1] Then $aReturn[5] = False
	For $i = 0 To 5
		If $aReturn[$i] Then $iCnt += 1
	Next
	If $iCnt < 2 Then Return SetError(1, 0, $aReturn)
	Return SetError(0, 0, $aReturn)
EndFunc   ;==>_GetVisible

Func _DrawPathRectRotate($hGraphics, $nAngle, $iX, $iY, $iXO, $iYO, $nDX, $nDY, $aPoints, $aBounds, $aVis, $hPen, $aData = 0, $iAx = 0)
	Local $aDataTemp
	Local $hPath = _GDIPlus_PathCreate($FillModeWinding)
	Local $hMatrix = _GDIPlus_MatrixCreate()
	Local $aP[5][2]
	$aP[0][0] = 4
	$aP[1][0] = $aBounds[0]
	$aP[1][1] = $aBounds[1]
	$aP[2][0] = $aBounds[0] + $aBounds[2]
	$aP[2][1] = $aBounds[1]
	$aP[3][0] = $aBounds[0]
	$aP[3][1] = $aBounds[1] + $aBounds[3]
	$aP[4][0] = $aBounds[0] + $aBounds[2]
	$aP[4][1] = $aBounds[1] + $aBounds[3]

	_GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")
	_GDIPlus_PathAddRectangle($hPath, $iX, $iY, 1, 1)

	_GDIPlus_PathWarp($hPath, $hMatrix, $aP, $aBounds[0] + $nDX, $aBounds[1] + $nDY, $aBounds[2], $aBounds[3])

	_GDIPlus_PathWarp($hPath, 0, $aPoints, $aBounds[0] - $iXO - $nDX, $aBounds[1] - $iYO - $nDY, $aBounds[2], $aBounds[3])
	$aDataTemp = _GDIPlus_PathGetData($hPath)

	If IsArray($aData) And $aData[0][0] = $aDataTemp[0][0] Then
		Local $hPathDraw = _GDIPlus_PathCreate($FillModeWinding)
		For $i = 1 To 4
			Switch $iAx
				Case 0 ; X-Achse
					Switch $i
						Case 1
							If $aVis[0] And $aVis[2] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[1][0], $aData[1][1], $aData[2][0], $aData[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[2] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[1][0], $aDataTemp[1][1], $aDataTemp[2][0], $aDataTemp[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[2] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[1][0], $aData[1][1], $aDataTemp[1][0], $aDataTemp[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
						Case 2
							If $aVis[0] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[2][0], $aData[2][1], $aData[3][0], $aData[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[2][0], $aDataTemp[2][1], $aDataTemp[3][0], $aDataTemp[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[2] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[2][0], $aData[2][1], $aDataTemp[2][0], $aDataTemp[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
						Case 3
							If $aVis[0] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[3][0], $aData[3][1], $aData[4][0], $aData[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[3][0], $aDataTemp[3][1], $aDataTemp[4][0], $aDataTemp[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[3] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[3][0], $aData[3][1], $aDataTemp[3][0], $aDataTemp[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
						Case 4
							If $aVis[0] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[4][0], $aData[4][1], $aData[1][0], $aData[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[4][0], $aDataTemp[4][1], $aDataTemp[1][0], $aDataTemp[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[3] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[4][0], $aData[4][1], $aDataTemp[4][0], $aDataTemp[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
					EndSwitch
				Case 1 ; Y-Achse
					Switch $i
						Case 1
							If $aVis[0] And $aVis[2] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[1][0], $aData[1][1], $aData[2][0], $aData[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[0] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[1][0], $aDataTemp[1][1], $aDataTemp[2][0], $aDataTemp[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[0] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[1][0], $aData[1][1], $aDataTemp[1][0], $aDataTemp[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf

						Case 2
							If $aVis[2] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[2][0], $aData[2][1], $aData[3][0], $aData[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[3] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[2][0], $aDataTemp[2][1], $aDataTemp[3][0], $aDataTemp[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[0] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[2][0], $aData[2][1], $aDataTemp[2][0], $aDataTemp[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
						Case 3
							If $aVis[1] And $aVis[2] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[3][0], $aData[3][1], $aData[4][0], $aData[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[3][0], $aDataTemp[3][1], $aDataTemp[4][0], $aDataTemp[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[3][0], $aData[3][1], $aDataTemp[3][0], $aDataTemp[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
						Case 4
							If $aVis[2] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[4][0], $aData[4][1], $aData[1][0], $aData[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[3] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[4][0], $aDataTemp[4][1], $aDataTemp[1][0], $aDataTemp[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[4][0], $aData[4][1], $aDataTemp[4][0], $aDataTemp[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
					EndSwitch
				Case 2
					Switch $i
						Case 1
							If $aVis[2] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[1][0], $aData[1][1], $aData[2][0], $aData[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[2] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[1][0], $aDataTemp[1][1], $aDataTemp[2][0], $aDataTemp[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[0] And $aVis[2] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[1][0], $aData[1][1], $aDataTemp[1][0], $aDataTemp[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf

						Case 2
							If $aVis[4] And $aVis[1] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[2][0], $aData[2][1], $aData[3][0], $aData[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[5] And $aVis[1] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[2][0], $aDataTemp[2][1], $aDataTemp[3][0], $aDataTemp[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[2] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[2][0], $aData[2][1], $aDataTemp[2][0], $aDataTemp[2][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
						Case 3
							If $aVis[4] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[3][0], $aData[3][1], $aData[4][0], $aData[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[5] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[3][0], $aDataTemp[3][1], $aDataTemp[4][0], $aDataTemp[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[1] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[3][0], $aData[3][1], $aDataTemp[3][0], $aDataTemp[3][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
						Case 4
							If $aVis[0] And $aVis[4] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[4][0], $aData[4][1], $aData[1][0], $aData[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[0] And $aVis[5] Then
								_GDIPlus_PathAddLine($hPathDraw, $aDataTemp[4][0], $aDataTemp[4][1], $aDataTemp[1][0], $aDataTemp[1][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
							If $aVis[0] And $aVis[3] Then
								_GDIPlus_PathAddLine($hPathDraw, $aData[4][0], $aData[4][1], $aDataTemp[4][0], $aDataTemp[4][1])
								_GDIPlus_PathCloseFigure($hPathDraw)
							EndIf
					EndSwitch
			EndSwitch
		Next
		If $hPen Then _GDIPlus_GraphicsDrawPath($hGraphics, $hPathDraw, $hPen)
		_GDIPlus_PathDispose($hPathDraw)
	EndIf
	_GDIPlus_PathDispose($hPath)
	_GDIPlus_MatrixDispose($hMatrix)
	Return $aDataTemp
EndFunc   ;==>_DrawPathRectRotate


Func _RotateBlock(ByRef $aBlock, $nAX, $nAY, $nAZ, ByRef $iXPos, ByRef $iYPos, ByRef $iZPos)
	;Return
	;_ArrayDisplayTree($aBlock)
	Local $aNew[5][5][5]
	Local $iX = $aBlock[0][1][0]
	Local $iY = $aBlock[0][2][0]
	Local $iZ = $aBlock[0][3][0]
	Local $iRX = $aBlock[0][1][1]
	Local $iRY = $aBlock[0][2][1]
	Local $iRZ = $aBlock[0][3][1]
	Select
		Case $nAX
			$aNew[0][1][0] = $iX
			$aNew[0][2][0] = $iZ
			$aNew[0][3][0] = $iY
			$aNew[0][1][1] = $iRX
			$aNew[0][2][1] = $iRZ
			$aNew[0][3][1] = $iY - $iRY
			$iYPos += $iRY - $iRZ
			$iZPos += $iRZ - $aNew[0][3][1]
			For $x = 1 To $iX
				For $y = 1 To $iY
					For $z = 1 To $iZ
						$aNew[$x][$z][$iY - $y + 1] = $aBlock[$x][$y][$z]
					Next
				Next
			Next
		Case $nAY
			$aNew[0][1][0] = $iZ
			$aNew[0][2][0] = $iY
			$aNew[0][3][0] = $iX
			$aNew[0][1][1] = $iRZ
			$aNew[0][2][1] = $iRY
			$aNew[0][3][1] = $iX - $iRX
			$iXPos += $iRX - $iRZ
			$iZPos += $iRZ - $aNew[0][3][1]
			For $x = 1 To $iX
				For $y = 1 To $iY
					For $z = 1 To $iZ
						$aNew[$z][$y][$iX - $x + 1] = $aBlock[$x][$y][$z]
					Next
				Next
			Next
		Case $nAZ
			$aNew[0][1][0] = $iY
			$aNew[0][2][0] = $iX
			$aNew[0][3][0] = $iZ
			$aNew[0][1][1] = $iY - $iRY
			$aNew[0][2][1] = $iRX
			$aNew[0][3][1] = $iRZ
			$iYPos += $iRY - $iRX
			$iXPos += $iRX - $aNew[0][1][1]
			For $x = 1 To $iX
				For $y = 1 To $iY
					For $z = 1 To $iZ
						$aNew[$iY - $y + 1][$x][$z] = $aBlock[$x][$y][$z]
					Next
				Next
			Next
	EndSelect
	$aBlock = $aNew
EndFunc   ;==>_RotateBlock



Func _DrawField($hGraphics, $aField, $aPathX, $aPathY, $aPathZ, $aC, $aBrush, $hPen)
	Local $hPath, $aPoints, $aBounds
	For $z = $aC[2] - 1 To 0 Step -1
		For $y = 0 To $aC[1] - 1
			For $x = 0 To $aC[0] - 1
				If $aField[$x][$y][$z] Then
					Switch $x
						Case $aC[0] / 2 To $aC[0]
							If Not $aField[$x - 1][$y][$z] Then _DrawPathRect($hGraphics, $z, $y, $aPathX[$x][1], $aPathX[$x][2], $aBrush[Mod($z, 8)], $hPen)
						Case 0 To $aC[0] / 2 - 1
							If Not $aField[$x + 1][$y][$z] Then _DrawPathRect($hGraphics, $z, $y, $aPathX[$x + 1][1], $aPathX[$x + 1][2], $aBrush[Mod($z, 8)], $hPen)
					EndSwitch
					Switch $y
						Case $aC[1] / 2 To $aC[1]
							If Not $aField[$x][$y - 1][$z] Then _DrawPathRect($hGraphics, $z, $x, $aPathY[$y][1], $aPathY[$y][2], $aBrush[Mod($z, 8)], $hPen)
						Case 0 To $aC[1] / 2 - 1
							If Not $aField[$x][$y + 1][$z] Then _DrawPathRect($hGraphics, $z, $x, $aPathY[$y + 1][1], $aPathY[$y + 1][2], $aBrush[Mod($z, 8)], $hPen)
					EndSwitch
				EndIf
			Next
		Next
		For $y = 0 To $aC[1] - 1
			For $x = 0 To $aC[0] - 1
				If $aField[$x][$y][$z] Then _DrawPathRect($hGraphics, $x, $y, $aPathZ[$z + 2][1], $aPathZ[$z + 2][2], $aBrush[Mod($z, 8)], $hPen)
			Next
		Next
	Next
EndFunc   ;==>_DrawField

Func _DrawPathRect($hGraphics, $iX, $iY, $aPoints, $aBounds, $hBrush, $hPen)
	Local $hPath = _GDIPlus_PathCreate($FillModeWinding)
	_GDIPlus_PathAddRectangle($hPath, $iX, $iY, 1, 1)
	_GDIPlus_PathWarp($hPath, 0, $aPoints, $aBounds[0], $aBounds[1], $aBounds[2], $aBounds[3])
	If $hBrush Then _GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush)
	If $hPen Then _GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen)
	_GDIPlus_PathDispose($hPath)
EndFunc   ;==>_DrawPathRect

Func _CreatePathX($iW, $iH, $aC, $nP)
	Local $aReturn[$aC[0] + 1][3];0:Path, 1:aPoints, 2:aBounds
	Local $aPoints[5][2], $aBounds[4] = [0, 0, $aC[2], $aC[1]]
	For $i = 0 To $aC[0]
		$aReturn[$i][0] = _GDIPlus_PathCreate($FillModeWinding)
		$aPoints[0][0] = 4

		$aPoints[1][0] = Round(($iW / $aC[0]) * $i)
		If $aPoints[1][0] = $iW / 2 Then $aPoints[1][0] += 1
		$aPoints[1][1] = 0

		$aPoints[2][0] = $iW / 2 - ($iW / 2 * $nP) + $aPoints[1][0] * $nP
		$aPoints[2][1] = $iH / 2 - ($iH / 2 * $nP)

		$aPoints[3][0] = $aPoints[1][0]
		$aPoints[3][1] = $iH

		$aPoints[4][0] = $aPoints[2][0]
		$aPoints[4][1] = $iH / 2 + ($iH / 2 * $nP)

		$aReturn[$i][1] = $aPoints

		_GDIPlus_PathAddRectangle($aReturn[$i][0], 0, 0, $aC[2], $aC[1])
		$aReturn[$i][2] = $aBounds
	Next
	Return $aReturn
EndFunc   ;==>_CreatePathX


Func _CreatePathY($iW, $iH, $aC, $nP)
	Local $aReturn[$aC[1] + 1][3];0:Path, 1:aPoints, 2:aBounds
	Local $aPoints[5][2], $aBounds[4] = [0, 0, $aC[2], $aC[0]]
	For $i = 0 To $aC[1]
		$aReturn[$i][0] = _GDIPlus_PathCreate($FillModeWinding)
		$aPoints[0][0] = 4

		$aPoints[1][0] = 0
		$aPoints[1][1] = Round(($iH / $aC[1]) * $i)
		If $aPoints[1][1] = $iH / 2 Then $aPoints[1][1] += 1

		$aPoints[2][0] = $iW / 2 - ($iW / 2 * $nP)
		$aPoints[2][1] = $iH / 2 - ($iH / 2 * $nP) + $aPoints[1][1] * $nP

		$aPoints[4][0] = $iW / 2 + ($iW / 2 * $nP)
		$aPoints[4][1] = $aPoints[2][1]

		$aPoints[3][0] = $iW
		$aPoints[3][1] = $aPoints[1][1]

		$aReturn[$i][1] = $aPoints

		_GDIPlus_PathAddRectangle($aReturn[$i][0], 0, 0, $aC[2], $aC[0])
		$aReturn[$i][2] = $aBounds
	Next
	Return $aReturn
EndFunc   ;==>_CreatePathY




Func _CreatePathZ($aPathX, $aC)
	Local $aReturn[$aC[2] + 3][3];0:Path, 1:aPoints, 2:aBounds
	Local $hPathLeft = _GDIPlus_PathCreate($FillModeWinding)
	Local $hPathRight = _GDIPlus_PathCreate($FillModeWinding)
	For $i = 0 To $aC[2] + 2
		_GDIPlus_PathAddLine($hPathLeft, $i, 0, $i, 1)
		_GDIPlus_PathAddLine($hPathRight, $i, $aC[1], $i, $aC[1] - 1)
	Next
	Local $aPoints, $aBounds, $aDataLeft, $aDataRight
	$aPoints = $aPathX[0][1]
	$aBounds = $aPathX[0][2]
	_GDIPlus_PathWarp($hPathLeft, 0, $aPoints, $aBounds[0] + 2, $aBounds[1], $aBounds[2], $aBounds[3])
	$aPoints = $aPathX[$aC[0]][1]
	$aBounds = $aPathX[$aC[0]][2]
	_GDIPlus_PathWarp($hPathRight, 0, $aPoints, $aBounds[0] + 2, $aBounds[1], $aBounds[2], $aBounds[3])
	$aBounds[0] = 0
	$aBounds[1] = 0
	$aBounds[2] = $aC[0]
	$aBounds[3] = $aC[1]
	$aDataLeft = _GDIPlus_PathGetData($hPathLeft)
	$aDataRight = _GDIPlus_PathGetData($hPathRight)
	_GDIPlus_PathDispose($hPathLeft)
	_GDIPlus_PathDispose($hPathRight)
	For $i = 0 To $aC[2] + 2
		$aReturn[$i][0] = _GDIPlus_PathCreate($FillModeWinding)
		$aPoints[0][0] = 4

		$aPoints[1][0] = $aDataLeft[$i * 2 + 1][0]
		$aPoints[1][1] = $aDataLeft[$i * 2 + 1][1] + $i * 0.01

		$aPoints[2][0] = $aDataRight[$i * 2 + 1][0]
		$aPoints[2][1] = $aDataLeft[$i * 2 + 1][1] + $i * 0.01

		$aPoints[3][0] = $aDataLeft[$i * 2 + 1][0]
		$aPoints[3][1] = $aDataRight[$i * 2 + 1][1] + $i * 0.01

		$aPoints[4][0] = $aDataRight[$i * 2 + 1][0]
		$aPoints[4][1] = $aDataRight[$i * 2 + 1][1] + $i * 0.01

		$aReturn[$i][1] = $aPoints

		_GDIPlus_PathAddRectangle($aReturn[$i][0], 0, 0, $aC[0], $aC[1])
		$aReturn[$i][2] = $aBounds
	Next

	Return $aReturn
EndFunc   ;==>_CreatePathZ

Func _CreatePathGrid($aPathX, $aPathY, $aPathZ, $aC)
	Local $hReturn = _GDIPlus_PathCreate($FillModeWinding)
	Local $hPath = _GDIPlus_PathCreate($FillModeWinding)
	Local $hPathClone
	For $i = 0 To $aC[2]
		_GDIPlus_PathAddLine($hPath, $i, 0, $i, $aC[1])
		_GDIPlus_PathCloseFigure($hPath)
	Next
	For $i = 0 To $aC[1]
		_GDIPlus_PathAddLine($hPath, 0, $i, $aC[2], $i)
		_GDIPlus_PathCloseFigure($hPath)
	Next

	Local $aPoints, $aBounds, $aDataLeft, $aDataRight
	$aPoints = $aPathX[0][1]
	$aBounds = $aPathX[0][2]
	$hPathClone = _GDIPlus_PathClone($hPath)
	_GDIPlus_PathWarp($hPathClone, 0, $aPoints, $aBounds[0], $aBounds[1], $aBounds[2], $aBounds[3])
	_GDIPlus_PathAddPath($hReturn, $hPathClone)
	_GDIPlus_PathDispose($hPathClone)

	$aPoints = $aPathX[$aC[0]][1]
	$aBounds = $aPathX[$aC[0]][2]
	$hPathClone = _GDIPlus_PathClone($hPath)
	_GDIPlus_PathWarp($hPathClone, 0, $aPoints, $aBounds[0], $aBounds[1], $aBounds[2], $aBounds[3])
	_GDIPlus_PathAddPath($hReturn, $hPathClone)
	_GDIPlus_PathDispose($hPathClone)
	_GDIPlus_PathDispose($hPath)

	$hPath = _GDIPlus_PathCreate($FillModeWinding)
	For $i = 0 To $aC[2]
		_GDIPlus_PathAddLine($hPath, $i, 0, $i, $aC[0])
		_GDIPlus_PathCloseFigure($hPath)
	Next
	For $i = 0 To $aC[0]
		_GDIPlus_PathAddLine($hPath, 0, $i, $aC[2], $i)
		_GDIPlus_PathCloseFigure($hPath)
	Next

	$aPoints = $aPathY[0][1]
	$aBounds = $aPathY[0][2]
	$hPathClone = _GDIPlus_PathClone($hPath)
	_GDIPlus_PathWarp($hPathClone, 0, $aPoints, $aBounds[0], $aBounds[1], $aBounds[2], $aBounds[3])
	_GDIPlus_PathAddPath($hReturn, $hPathClone)
	_GDIPlus_PathDispose($hPathClone)

	$aPoints = $aPathY[$aC[1]][1]
	$aBounds = $aPathY[$aC[1]][2]
	$hPathClone = _GDIPlus_PathClone($hPath)
	_GDIPlus_PathWarp($hPathClone, 0, $aPoints, $aBounds[0], $aBounds[1], $aBounds[2], $aBounds[3])
	_GDIPlus_PathAddPath($hReturn, $hPathClone)
	_GDIPlus_PathDispose($hPathClone)

	_GDIPlus_PathDispose($hPath)

	$hPath = _GDIPlus_PathCreate($FillModeWinding)
	For $i = 0 To $aC[0]
		_GDIPlus_PathAddLine($hPath, $i, 0, $i, $aC[1])
		_GDIPlus_PathCloseFigure($hPath)
	Next
	For $i = 0 To $aC[1]
		_GDIPlus_PathAddLine($hPath, 0, $i, $aC[0], $i)
		_GDIPlus_PathCloseFigure($hPath)
	Next

	$aPoints = $aPathZ[$aC[2] + 2][1]
	$aBounds = $aPathZ[$aC[2] + 2][2]
	$hPathClone = _GDIPlus_PathClone($hPath)
	_GDIPlus_PathWarp($hPathClone, 0, $aPoints, $aBounds[0], $aBounds[1], $aBounds[2], $aBounds[3])
	_GDIPlus_PathAddPath($hReturn, $hPathClone)
	_GDIPlus_PathDispose($hPathClone)
	_GDIPlus_PathDispose($hPath)

	Return $hReturn
EndFunc   ;==>_CreatePathGrid


Func _CreateBackGround($hGraphics, $iW, $iH, $nP, $nColor1 = 0xFF020204, $nColor2 = 0xFF131326, $nColor3 = 0xFF242448)

	Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
	Local $hGfxBitmap = _GDIPlus_ImageGetGraphicsContext($hBitmap)
	_GDIPlus_GraphicsSetSmoothingMode($hGfxBitmap, 2)
	Local $hBrush, $aP[5][2] = [[4]]
	$aP[1][0] = 0
	$aP[1][1] = 0
	$aP[2][0] = $iW / 2 - ($iW / 2 * $nP)
	$aP[2][1] = $iH / 2 - ($iH / 2 * $nP)
	$aP[3][0] = $iW / 2 - ($iW / 2 * $nP)
	$aP[3][1] = $iH / 2 + ($iH / 2 * $nP)
	$aP[4][0] = 0
	$aP[4][1] = $iH
	$hBrush = _GDIPlus_LineBrushCreate($aP[2][0], $aP[2][1], $aP[4][0], $aP[4][1], $nColor1, $nColor2, 1)
	_GDIPlus_GraphicsFillPolygon($hGfxBitmap, $aP, $hBrush)
	_GDIPlus_BrushDispose($hBrush)

	$aP[1][0] = 0
	$aP[1][1] = 0
	$aP[2][0] = $iW / 2 - ($iW / 2 * $nP)
	$aP[2][1] = $iH / 2 - ($iH / 2 * $nP)
	$aP[3][0] = $iW / 2 + ($iW / 2 * $nP)
	$aP[3][1] = $iH / 2 - ($iH / 2 * $nP)
	$aP[4][0] = $iW
	$aP[4][1] = 0
	$hBrush = _GDIPlus_LineBrushCreate($aP[2][0], $aP[2][1], $aP[4][0], $aP[4][1], $nColor1, $nColor2, 1)
	_GDIPlus_GraphicsFillPolygon($hGfxBitmap, $aP, $hBrush)
	_GDIPlus_BrushDispose($hBrush)

	$aP[1][0] = $iW / 2 - ($iW / 2 * $nP)
	$aP[1][1] = $iH / 2 - ($iH / 2 * $nP)
	$aP[2][0] = $iW / 2 + ($iW / 2 * $nP)
	$aP[2][1] = $iH / 2 - ($iH / 2 * $nP)
	$aP[3][0] = $iW / 2 + ($iW / 2 * $nP)
	$aP[3][1] = $iH / 2 + ($iH / 2 * $nP)
	$aP[4][0] = $iW / 2 - ($iW / 2 * $nP)
	$aP[4][1] = $iH / 2 + ($iH / 2 * $nP)
	$hBrush = _GDIPlus_LineBrushCreate($aP[1][0], $aP[1][1], $aP[3][0], $aP[3][1], $nColor1, $nColor2, 1)
	_GDIPlus_GraphicsFillPolygon($hGfxBitmap, $aP, $hBrush)
	_GDIPlus_BrushDispose($hBrush)

	$aP[1][0] = $iW / 2 + ($iW / 2 * $nP)
	$aP[1][1] = $iH / 2 - ($iH / 2 * $nP)
	$aP[2][0] = $iW
	$aP[2][1] = 0
	$aP[3][0] = $iW
	$aP[3][1] = $iH
	$aP[4][0] = $iW / 2 + ($iW / 2 * $nP)
	$aP[4][1] = $iH / 2 + ($iH / 2 * $nP)
	$hBrush = _GDIPlus_LineBrushCreate($aP[1][0], $aP[1][1], $aP[3][0], $aP[3][1], $nColor2, $nColor3, 1)
	_GDIPlus_GraphicsFillPolygon($hGfxBitmap, $aP, $hBrush)
	_GDIPlus_BrushDispose($hBrush)

	$aP[1][0] = $iW / 2 - ($iW / 2 * $nP)
	$aP[1][1] = $iH / 2 + ($iH / 2 * $nP)
	$aP[2][0] = $iW / 2 + ($iW / 2 * $nP)
	$aP[2][1] = $iH / 2 + ($iH / 2 * $nP)
	$aP[3][0] = $iW
	$aP[3][1] = $iH
	$aP[4][0] = 0
	$aP[4][1] = $iH
	$hBrush = _GDIPlus_LineBrushCreate($aP[1][0], $aP[1][1], $aP[3][0], $aP[3][1], $nColor2, $nColor3, 1)
	_GDIPlus_GraphicsFillPolygon($hGfxBitmap, $aP, $hBrush)
	_GDIPlus_BrushDispose($hBrush)

	_GDIPlus_GraphicsDispose($hGfxBitmap)
	Return $hBitmap
EndFunc   ;==>_CreateBackGround


Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT

Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
	_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
	Return True
EndFunc   ;==>WM_ERASEBKGND

Func _Exit()
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_PenDispose($hPen)
	_GDIPlus_GraphicsDispose($hGfxBuffer)
	_GDIPlus_BitmapDispose($hBmpBuffer)
	_GDIPlus_GraphicsDispose($hGraphics)
	_GDIPlus_Shutdown()
	Exit
EndFunc   ;==>_Exit