Sign in to follow this  
Followers 0
AlmarM

Drawing a parabola

3 posts in this topic

Hi,

does anyone has an UDF for drawing a parabola?

Posted Image

I never saw one before. :mellow:


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites



You can use e.g GDI+ to draw it -> http://www.autoitscript.com/forum/index.php?showtopic=115684

BR,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks. :P

EDIT: Oh gawd. Which functions are used to create the parabola?

I can't seem to figure out :mellow:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w1 -w2 -w3 -w4 -w5 -w6
#AutoIt3Wrapper_UseUpx=Y
#AutoIt3Wrapper_Compression=4
#Autoit3Wrapper_Run_Obfuscator=Y
#Obfuscator_Parameters=/SO
#include <Array.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
Opt("GUIOnEventMode", 1)

; Graphic binaries
Local $bBallR = '0x89504E470D0A1A0A0000000D494844520000000B0000000B0806000000A9AC77260000000467414D410000B18F0BFC61050000001974455874536F667477617265005061696E742E4E45542076332E352E314EE738F90000003649444154285363644002FF191880081530323000111A0029C4855194E2530893036B2046215CC350544CAC2749093E0EA22206591100760BBA5107CF97330000000049454E44AE426082'

; Distance traveled
; g: the gravitational acceleration
; a: the angle at which the projectile is launched
; v: the velocity at which the projectile is launched
; y: the initial height of the projectile
; d: the total horizontal distance traveled by the projectile
Local $g = 10
Local $a = 60
Local $v = 75
Local $y = 0
$a = $a / 57.2957795130823 ; Convert angle from degrees to radians
Local $d = (($v * Cos($a)) / $g) * ($v * Sin($a) + Sqrt((($v * Sin($a)) ^ 2) + (2 * $g * $y)))

; Calculate the trajectory
Local $aPoints[1][2], $j = 1
For $i = 0 To $d
    $j += 1
    ReDim $aPoints[$j][2]
    $aPoints[$j - 1][0] = $i
    $aPoints[$j - 1][1] = 600 - ($y + ($i * Tan($a)) - ($g * ($i ^ 2)) / (2 * (($v * Cos($a)) ^ 2)))
Next
$aPoints[0][0] = UBound($aPoints) - 1

; Create the GUI
Local $hWnd = GUICreate("Trajectory Test", 800, 600)
GUISetBkColor(0x000000); Black background
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

GUICtrlCreateLabel("Label", 200, 100, 50, 20)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlCreateInput("Input", 200, 450, 50, 20, 0x01)
GUICtrlSetColor(-1, 0x000000)
GUICtrlCreateButton("Button", 200, 300, 50, 20)
GUICtrlSetColor(-1, 0x000000)

GUISetState()

_GDIPlus_Startup()
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Local $hImage = _GDIPlus_BitmapCreateFromGraphics(800, 600, $hGraphics)
Local $hImageFx = _GDIPlus_ImageGetGraphicsContext($hImage)
Local $hImageCurve = _GDIPlus_BitmapCreateFromGraphics(800, 600, $hGraphics)
Local $hImageCurveFx = _GDIPlus_ImageGetGraphicsContext($hImageCurve)
Local $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 1)
Local $hBallImg = _GDIPlus_BinaryToBitmap($bBallR)

GUIRegisterMsg(0x000F, "_WM_PAINT")
_GDIPlus_GraphicsSetSmoothingMode($hImageCurveFx, 4)

; Draw the Trajectory
_GDIPlus_GraphicsDrawCurve($hImageCurveFx, $aPoints, $hPen)
_GDIPlus_GraphicsDispose($hImageCurveFx)

Local $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, 800, 600))
Local $hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)
Local $aRect

Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild

_GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion)
_GDIPlus_RegionDispose($hRegion)

; Draw a red ball following the trajectory
For $i = 1 To $aPoints[0][0]
    _GDIPlus_GraphicsClear($hImageFx)
    _GDIPlus_GraphicsDrawImage($hImageFx, $hImageCurve, 0, 0)
    _GDIPlus_GraphicsDrawImage($hImageFx, $hBallImg, $aPoints[$i][0] - 5, $aPoints[$i][1] - 5)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 0, 0)
    Sleep(10)
Next

While 1
    Sleep(20)
WEnd

Func _Quit()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBallImg)
    _GDIPlus_BitmapDispose($hImageCurve)
    _GDIPlus_GraphicsDispose($hImageFx)
    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc

Func _GDIPlus_BinaryToBitmap($Binary)
    Local $bPicData = Binary($Binary)
    Local $iPicLength = BinaryLen($bPicData)
    Local $tPicStruct = DllStructCreate("byte[" & $iPicLength & "]")
    DllStructSetData($tPicStruct, 1, $bPicData)
    Local $pPicMemory = DllStructGetPtr($tPicStruct)
    Local $hMemory = _MemGlobalAlloc($iPicLength, 2)
    Local $pMemory = _MemGlobalLock($hMemory)
    _MemMoveMemory($pPicMemory, $pMemory, $iPicLength)
    _MemGlobalUnlock($hMemory)
    Local $pStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "int", $hMemory, "long", 1, "Int*", 0)
    $pStream = $pStream[3]
    Local $pBitmap = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0)
    $pBitmap = $pBitmap[2]
    $tPicStruct = 0
    Return $pBitmap
EndFunc

Func _WM_PAINT($hWnd, $iMsg, $iwParam, $ilParam)
    Sleep(20)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 0, 0)
    Return 'GUI_RUNDEFMSG'
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_GraphicsSetClipRegion
; Description ...: Updates the clipping region of a Graphics object to a region that is the combination of itself and the region
;                  +specified by a Region object
; Syntax.........: _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion[, $iCombineMode = 0])
; Parameters ....: $hGraphics - Pointer to a Graphics object
;                  $hRegion   - Pointer to a Region object to be combined with the clipping region of the Graphics object
;                  $iCombineMode - Regions combination mode:
;                  |0 - The existing region is replaced by the new region
;                  |1 - The existing region is replaced by the intersection of itself and the new region
;                  |2 - The existing region is replaced by the union of itself and the new region
;                  |3 - The existing region is replaced by the result of performing an XOR on the two regions
;                  |4 - The existing region is replaced by the portion of itself that is outside of the new region
;                  |5 - The existing region is replaced by the portion of the new region that is outside of the existing region
; Return values .: Success      - True
;                  Failure      - False
; Remarks .......: None
; Related .......: None
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)

    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_GraphicsSetClipRegion

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_RegionCreateFromRect
; Description ...: Creates a region that is defined by a rectangle
; Syntax.........: _GDIPlus_RegionCreateFromRect($tRectF)
; Parameters ....: $tRectF - $tagGDIPRECTF structure that specifies the bounding rectangle of the region
; Return values .: Success      - Pointer to a new Region object
;                  Failure      - 0
; Remarks .......: After you are done with the object, call _GDIPlus_RegionDispose to release the object resources
; Related .......: _GDIPlus_RegionDispose
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult

    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_RegionCreateFromRect

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_RegionCombineRect
; Description ...: Updates a region to the portion of itself that intersects the specified rectangle's interior
; Syntax.........: _GDIPlus_RegionCombineRect($hRegion, $tRectF[, $iCombineMode = 2])
; Parameters ....: $hRegion      - Pointer to a Region object
;                  $tRectF       - $tagGDIPRECTF structure that defines the bounding rectangle
;                  $iCombineMode - Combine mode that specifies how the region is combined with the rectangle:
;                  |0 - The existing region is replaced by the new region
;                  |1 - The existing region is replaced by the intersection of itself and the new region
;                  |2 - The existing region is replaced by the union of itself and the new region
;                  |3 - The existing region is replaced by the result of performing an XOR on the two regions.
;                  +A point is in the XOR of two regions if it is in one region or the other but not in both regions
;                  |4 - The existing region is replaced by the portion of itself that is outside of the new region
;                  |5 - The existing region is replaced by the portion of the new region that is outside of the existing region
; Return values .: Success      - True
;                  Failure      - False
; Remarks .......: None
; Related .......: None
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult

    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)

    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionCombineRect

; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_RegionDispose
; Description ...: Releases a Region object
; Syntax.........: _GDIPlus_RegionDispose($hRegion)
; Parameters ....: $hRegion - Pointer to a Region object
; Return values .: Success      - True
;                  Failure      - False
; Remarks .......: None
; Related .......: None
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)

    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc   ;==>_GDIPlus_RegionDispose
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0