Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WindowsConstants.au3>
- #include <GUIConstants.au3>
- #include <GDIPlus.au3>
- #include <WinAPI.au3>
- ; -Author: name22 (www.autoit.de)
- Opt("GUIOnEventMode", 1)
- Global $vA[2], $vB[2], $vDir[2], $nLen, $nSpeed, $nPos = 0
- $nSpeed = 3 ;Der blaue Punkt wandert pro Schleifendurchgang 3 Pixel entlang der Linie
- ;Punkte festlegen:
- $vA[0] = 10 ;X-Koordinate von A
- $vA[1] = 20 ;Y-Koordinate von A
- $vB[0] = 256 ;X-Koordinate von A
- $vB[1] = 386 ;Y-Koordinate von A
- ;Richtungsvektor bestimmen (du musst nur den Startpunkt vom Zielpunkt abziehen, Koordinate für Koordinate):
- $vDir[0] = $vB[0] - $vA[0]
- $vDir[1] = $vB[1] - $vA[1]
- ;Richtungsvektor normalisieren (auf eine Länge von 1 reduzieren, so dass er seine Richtung beibehält):
- ;[dazu wird jede Koordinate durch die Gesamtlänge des Vektors (Pythagoras) geteilt]
- $nLen = Sqrt($vDir[0] ^ 2 + $vDir[1] ^ 2) ;Länge des Vektors (Strecke von A nach B)
- $vDir[0] = $vDir[0] / $nLen
- $vDir[1] = $vDir[1] / $nLen
- $hGUI = GUICreate("Example by name22", 400, 400)
- GUISetState()
- $hDC_Window = _WinAPI_GetDC($hGUI)
- $hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
- $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, 400, 400)
- _WinAPI_SelectObject($hDC_Bitmap, $hBitmap)
- _GDIPlus_Startup()
- $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Bitmap)
- _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
- $hBrush_Red = _GDIPlus_BrushCreateSolid(0xFFFF0000)
- $hBrush_Green = _GDIPlus_BrushCreateSolid(0xFF00FF00)
- $hBrush_Blue = _GDIPlus_BrushCreateSolid(0xFF0000FF)
- $hPen = _GDIPlus_PenCreate(0xFF000000, 3)
- OnAutoItExitRegister("_Shutdown")
- GUISetOnEvent($GUI_EVENT_CLOSE, "_Close", $hGUI)
- While Sleep(20)
- ;Nur eine kleine Spielerei um verschiedene Werte für nPos zu demonstrieren:
- $nPos += $nSpeed
- If $nPos >= $nLen Then
- $nPos = $nLen
- $nSpeed *= -1
- ElseIf $nPos <= 0 Then
- $nPos = 0
- $nSpeed *= -1
- EndIf
- $nX_Pos = $vA[0] + $vDir[0] * $nPos ;X-Koordinate des Punktes auf der Linie AB ausrechnen
- $nY_Pos = $vA[1] + $vDir[1] * $nPos ;Y-Koordinate des Punktes auf der Linie AB ausrechnen
- ;($nPos ist die Distanz von A in Pixeln, für nPos="0" ist die Postion="A", für nPos="Volle Länge von AB" ist die Position="B")
- _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)
- _GDIPlus_GraphicsDrawLine($hGraphics, $vA[0], $vA[1], $vB[0], $vB[1], $hPen)
- _GDIPlus_GraphicsFillEllipse($hGraphics, $vA[0] - 5, $vA[1] - 5, 10, 10, $hBrush_Green)
- _GDIPlus_GraphicsFillEllipse($hGraphics, $vB[0] - 5, $vB[1] - 5, 10, 10, $hBrush_Red)
- _GDIPlus_GraphicsFillEllipse($hGraphics, $nX_Pos - 8, $nY_Pos - 8, 16, 16, $hBrush_Blue)
- _WinAPI_BitBlt($hDC_Window, 0, 0, 400, 400, $hDC_Bitmap, 0, 0, $SRCCOPY)
- WEnd
- Func _Close()
- Exit
- EndFunc
- Func _Shutdown()
- _WinAPI_ReleaseDC($hGUI, $hDC_Window)
- _WinAPI_DeleteDC($hDC_Bitmap)
- _WinAPI_DeleteObject($hBitmap)
- _GDIPlus_GraphicsDispose($hGraphics)
- _GDIPlus_BrushDispose($hBrush_Red)
- _GDIPlus_BrushDispose($hBrush_Green)
- _GDIPlus_BrushDispose($hBrush_Blue)
- _GDIPlus_PenDispose($hPen)
- _GDIPlus_Shutdown()
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement