#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
; - Author: name22 (www.autoit.de)
Opt("GUIOnEventMode", 1)
Global Const $nPiHalf = ACos(-1) / 2
Global $hWnd_GUI, $hDC_Window, $hDC_Bitmap, $hBitmap
Global $nSleepTime, $nFPS_Average, $nFPS_Cur, $nFPS_Display, $tPrecSleep, $pPrecSleep, $vNTdll
Global $hGraphics, $hBrush_Black, $hBrush_Red, $hStringFormat, $hFamily_FPS, $hFont_FPS, $aMeasure, $tLayout_FPS
Global $nT_Sleep, $nT_UpdateFPS, $nT_Movement, $nMovementTime, $nMovementPhase, $nFrameTime
Global $nX_Source, $nY_Source, $nX_Pos, $nY_Pos, $nX_Target, $nY_Target
;###-v-SETTINGS-v-###
Global $iWidth = 600
Global $iHeight = 400
Global $iARGB_BG = 0xFFFFFFFF
Global $nFPS = 60
Global $nMovementDuration = 2000
$nX_Target = Random(20, $iWidth - 20, 1)
$nY_Target = Random(20, $iHeight - 20, 1)
;###-^-SETTINGS-^-###
$nSleepTime = 1000 / $nFPS
$nFPS_Display = 0
$nFPS_Average = $nFPS
$vNTdll = DllOpen("ntdll.dll")
$tPrecSleep = DllStructCreate("int64 time;")
$pPrecSleep = DllStructGetPtr($tPrecSleep)
$hWnd_GUI = GUICreate("Motion along linear path", $iWidth, $iHeight)
GUISetState()
$hDC_Window = _WinAPI_GetDC($hWnd_GUI)
$hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iWidth, $iHeight)
_WinAPI_SelectObject($hDC_Bitmap, $hBitmap)
_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Bitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
$hBrush_Black = _GDIPlus_BrushCreateSolid(0xFF000000)
$hBrush_Red = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$hStringFormat = _GDIPlus_StringFormatCreate()
$hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial")
$hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 6)
$aMeasure = _GDIPlus_GraphicsMeasureString($hGraphics, "FPS: 0000", $hFont_FPS, _GDIPlus_RectFCreate(), $hStringFormat)
$tLayout_FPS = $aMeasure[0]
$aMeasure = ""
DllStructSetData($tLayout_FPS, "X", $iWidth - DllStructGetData($tLayout_FPS, "Width") - 3)
DllStructSetData($tLayout_FPS, "Y", $iHeight - DllStructGetData($tLayout_FPS, "Height"))
DllStructSetData($tLayout_FPS, "Width", DllStructGetData($tLayout_FPS, "Width") + 3)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
OnAutoItExitRegister("_Shutdown")
$nT_UpdateFPS = TimerInit()
$nT_Sleep = TimerInit()
_SetNewTarget()
While True
DllStructSetData($tPrecSleep, "time", -10000 * ($nSleepTime - TimerDiff($nT_Sleep)))
DllCall($vNTdll, "dword", "ZwDelayExecution", "int", 0, "ptr", $pPrecSleep)
$nFrameTime = TimerDiff($nT_Sleep)
$nT_Sleep = TimerInit()
$nFPS_Cur = 1000 / $nFrameTime
If TimerDiff($nT_UpdateFPS) >= 1000 Then
$nFPS_Display = $nFPS_Cur
$nT_UpdateFPS = TimerInit()
EndIf
If TimerDiff($nT_Movement) >= $nMovementDuration Then _SetNewTarget()
$nMovementTime = TimerDiff($nT_Movement)
$nMovementPhase = _MovementTimingFunction($nMovementTime, $nMovementDuration)
$nX_Pos = $nX_Source + $nMovementPhase * ($nX_Target - $nX_Source)
$nY_Pos = $nY_Source + $nMovementPhase * ($nY_Target - $nY_Source)
_GDIPlus_GraphicsClear($hGraphics, $iARGB_BG)
_GDIPlus_GraphicsFillEllipse($hGraphics, $nX_Pos - 20, $nY_Pos - 20, 40, 40, $hBrush_Red)
_GDIPlus_GraphicsFillRect($hGraphics, $nX_Target - 2, $nY_Target - 2, 4, 4, $hBrush_Black)
_GDIPlus_GraphicsDrawStringEx($hGraphics, "FPS: " & Round($nFPS_Display, 1), $hFont_FPS, $tLayout_FPS, $hStringFormat, $hBrush_Black)
_WinAPI_BitBlt($hDC_Window, 0, 0, $iWidth, $iHeight, $hDC_Bitmap, 0, 0, $SRCCOPY)
WEnd
Func _Close()
Exit
EndFunc ;==>_Close
Func _SetNewTarget()
$nX_Source = $nX_Target
$nY_Source = $nY_Target
$nX_Target = Random(20, $iWidth - 20, 1)
$nY_Target = Random(20, $iHeight - 20, 1)
$nT_Movement = TimerInit()
EndFunc
Func _MovementTimingFunction($nTime, $nDuration)
Local $T = $nTime / $nDuration
Return $T ^ 2 * (3 - 2 * $T)
EndFunc
Func _Shutdown()
_WinAPI_ReleaseDC($hWnd_GUI, $hDC_Window)
_WinAPI_DeleteDC($hDC_Bitmap)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BrushDispose($hBrush_Black)
_GDIPlus_BrushDispose($hBrush_Red)
_GDIPlus_StringFormatDispose($hStringFormat)
_GDIPlus_FontFamilyDispose($hFamily_FPS)
_GDIPlus_FontDispose($hFont_FPS)
_GDIPlus_Shutdown()
DllClose($vNTdll)
EndFunc ;==>_Shutdown