Jump to content

Beizer Curve Parameters


YellowLab
 Share

Recommended Posts

I have been struggling with this for a while and can't figure out for the life of me how to generate a Beizer Curve using GUICtrlSetGraphic function. I have generated a list of Beizer points using the script from the following post (http://www.autoitscript.com/forum/index.php?showtopic=82782 - great script BTW) and now want to generate the curve using GUICtrlSetGraphic. From the help file, the function has six parameters labeled x,y,x1,y1,x2,y2 with a description - draw a Beizer curve with two control points. I am assuming this is correct; however the example doesn't seem to jibe with this:

GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 120, 20)    ; start point
GUICtrlSetGraphic(-1, $GUI_GR_BEZIER, 120, 100, 200, 20, 200, 100)

The starting point is x=120, y=20 then the curve has the parameters x, ?, ?, y, ?, ?

The script draws half an elipse and I can't figure out for the life of me how this works.

Any help would be appreciated.

Thanks!

Edited by YellowLab

You can't see a rainbow without first experiencing the rain.

Link to comment
Share on other sites

You need to read something like this.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Here is an better example of a $GUI_GR_BEZIER and a $GUI_GR_HINT graphic types of a GUI graphics control.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt('MustDeclareVars', 1)

Global $a, $b, $iFill = 2, $bDispCtrlPts = True
Local $hGui, $ButFill, $ButCtrlPts, $msg

$hGui = GUICreate("BEZIER Curve", 320, 345, 100, 100)
$ButFill = GUICtrlCreateButton("Toggle Fill", 20, 315)
$ButCtrlPts = GUICtrlCreateButton("Toggle Ctrl Pts", 100, 315)
$a = GUICtrlCreateGraphic(10, 10, 300, 300)
Example()
GUISetState()

Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $ButFill
            $iFill = Mod($iFill + 1, 3) ; 3 possibilities
            Example()
        Case $msg = $ButCtrlPts
            If $bDispCtrlPts = True Then ; 2 possibilities
                $bDispCtrlPts = False
            Else
                $bDispCtrlPts = True
            EndIf
            Example()
    EndSelect
Until $msg = $GUI_EVENT_CLOSE

Func Example()
    If $bDispCtrlPts Then
        GUICtrlSetGraphic($a, $GUI_GR_HINT) ; display control point and end point of bezier/line curve.
    Else
        GUICtrlDelete($a)
        $a = GUICtrlCreateGraphic(10, 10, 300, 300)
    EndIf

    Switch $iFill
        Case 0
            GUICtrlDelete($a)
            $a = GUICtrlCreateGraphic(10, 10, 300, 300)
            If $bDispCtrlPts Then GUICtrlSetGraphic($a, $GUI_GR_HINT)
        Case 1
            GUICtrlSetGraphic($a, $GUI_GR_COLOR, 0xff0000, 0xffffff); No Fill
        Case 2
            GUICtrlSetGraphic($a, $GUI_GR_COLOR, 0xff0000, 0xff0000); Fill
    EndSwitch

    GUICtrlSetBkColor($a, 0xffffff)
    GUICtrlSetGraphic($a, $GUI_GR_PENSIZE, 3)
    GUICtrlSetGraphic($a, $GUI_GR_MOVE, 5, 290) ; start point
    GUICtrlSetGraphic($a, $GUI_GR_BEZIER, 290, 290, 50, 5, 50, 100)

    GUICtrlSetGraphic($a, $GUI_GR_REFRESH) ; force refresh after dynamic update of graphics
    Return
EndFunc ;==>Example
Link to comment
Share on other sites

That's good Malkey. I added dragging the control points.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Misc.au3>

Opt('MustDeclareVars', 1)

Global $a, $b, $iFill = 2, $bDispCtrlPts = True
Local $hGui, $ButFill, $ButCtrlPts, $msg, $mp, $mp2

$hGui = GUICreate("BEZIER Curve", 320, 345, 100, 100)
$ButFill = GUICtrlCreateButton("Toggle Fill", 20, 315)
$ButCtrlPts = GUICtrlCreateButton("Toggle Ctrl Pts", 100, 315)
$a = GUICtrlCreateGraphic(10, 10, 300, 300)
Global $a1 = 50, $a2 = 5, $b1 = 50, $b2 = 100, $c, $d
Example()
GUISetState()


Do
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_PRIMARYDOWN
    If $bDispCtrlPts Then
    Opt("mousecoordmode", 2)
    $mp = MouseGetPos()
    ConsoleWrite($mp[0] & @CRLF)
    If Abs($mp[0] - $a1 - 10) < 3 And Abs($mp[1] - $a2 - 10) < 3 Then

    While _IsPressed(1)
    Opt("mousecoordmode", 1)
    $c = MouseGetPos(0) - 10
    $d = MouseGetPos(1) - 10
    Opt("mousecoordmode", 2)
    $a1 = MouseGetPos(0) - 10
    $a2 = MouseGetPos(1) - 10
    ToolTip($a1 & ', ' & $a2, $c, $d + 34)
    WEnd
    ToolTip("")
    example()
    EndIf
    If Abs($mp[0] - $b1 - 10) < 3 And Abs($mp[1] - $b2 - 10) < 3 Then
    While _IsPressed(1)
    Opt("mousecoordmode", 1)
    $c = MouseGetPos(0) - 10
    $d = MouseGetPos(1) - 10
    Opt("mousecoordmode", 2)
    $b1 = MouseGetPos(0) - 10
    $b2 = MouseGetPos(1) - 10
    ToolTip($b1 & ', ' & $b2, $c, $d + 34)
    WEnd
    ToolTip("")
    example()
    EndIf
    EndIf
    Case $msg = $ButFill
    $iFill = Mod($iFill + 1, 3) ; 3 possibilities
    Example()
    Case $msg = $ButCtrlPts
    If $bDispCtrlPts = True Then ; 2 possibilities
    $bDispCtrlPts = False
    Else
    $bDispCtrlPts = True
    EndIf
    Example()
    EndSelect
Until $msg = $GUI_EVENT_CLOSE

Func Example()
    GUICtrlDelete($a)
    $a = GUICtrlCreateGraphic(10, 10, 300, 300)
    If $bDispCtrlPts Then GUICtrlSetGraphic($a, $GUI_GR_HINT) ; display control point and end point of bezier/line curve.

    Switch $iFill
    Case 0
    GUICtrlDelete($a)
    $a = GUICtrlCreateGraphic(10, 10, 300, 300)
    If $bDispCtrlPts Then GUICtrlSetGraphic($a, $GUI_GR_HINT)
    Case 1
    GUICtrlSetGraphic($a, $GUI_GR_COLOR, 0xff0000, 0xffffff); No Fill
    Case 2
    GUICtrlSetGraphic($a, $GUI_GR_COLOR, 0xff0000, 0xff0000); Fill
    EndSwitch

    GUICtrlSetBkColor($a, 0xffffff)
    GUICtrlSetGraphic($a, $GUI_GR_PENSIZE, 3)
    GUICtrlSetGraphic($a, $GUI_GR_MOVE, 5, 290) ; start point
    GUICtrlSetGraphic($a, $GUI_GR_BEZIER, 290, 290, $a1, $a2, $b1, $b2)

    GUICtrlSetGraphic($a, $GUI_GR_REFRESH) ; force refresh after dynamic update of graphics
    Return
EndFunc ;==>Example
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Great minds think alike, or is it fools seldom differ.

... And this example is also re-sizable.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt('MustDeclareVars', 1)

Global $a, $b, $iFill = 2, $bDispCtrlPts = True
Global $aPts[4][2] = [[5, 290],[290, 290],[50, 5],[50, 100]]
Local $hGui, $ButFill, $ButCtrlPts, $ButPt1, $ButPt2, $ButPt3, $ButWritePts
Local $ButPt4, $sPts, $file, $msg
Local $ButAllPts, $aTemp, $aMPos, $aMPosNew

$hGui = GUICreate("BEZIER Curve", 320, 395, 100, 100, $WS_SIZEBOX)
$ButFill = GUICtrlCreateButton("Toggle Fill", 10, 315)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Toggle fill / no fill of bezier curve.")
$ButCtrlPts = GUICtrlCreateButton("Toggle Ctrl Pts", 70, 315)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Toggle show / hide control points of bezier curve.")
$ButPt1 = GUICtrlCreateButton("Ctrl Pt 1", 150, 315)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Click this button, then use mouse drag to adjust point")
$ButPt2 = GUICtrlCreateButton("Pt 1", 200, 315)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Click this button, then use mouse drag to adjust point")
$ButPt3 = GUICtrlCreateButton("Pt 2", 230, 315)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Click this button, then use mouse drag to adjust point")
$ButPt4 = GUICtrlCreateButton("Ctrl Pt 2", 260, 315)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Click this button, then use mouse drag to adjust point")

$ButWritePts = GUICtrlCreateButton("Write Pts", 10, 345)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Write all points to text file.")
$ButAllPts = GUICtrlCreateButton("Move All Pts", 70, 345)
GUICtrlSetResizing(-1, 768)
GUICtrlSetTip(-1, "Click this button, then use mouse drag to move all points.")

$a = GUICtrlCreateGraphic(10, 10, 300, 300)
GUICtrlSetResizing(-1, 102)
Example()
GUISetState()

Do
    $msg = GUIGetMsg()
    Switch $msg
        Case $ButFill
            $iFill = Mod($iFill + 1, 3) ; 3 possibilities
            Example()
        Case $ButCtrlPts
            If $bDispCtrlPts = True Then ; 2 possibilities
                $bDispCtrlPts = False
            Else
                $bDispCtrlPts = True
            EndIf
            Example()
        Case $ButWritePts
            $file = FileOpen("BezierData.txt", 9)
            $sPts = @CRLF & "========= " & @YEAR & "/" & @MON & "/" & @MDAY & _
                    " ==========" & @CRLF & "Global $aPts[4][2] = ["
            For $i = 0 To UBound($aPts) - 1
                $sPts &= "[" & $aPts[$i][0] & ", " & $aPts[$i][1] & "], "
            Next
            FileWrite($file, StringTrimRight($sPts, 2) & "]" & @CRLF)
            FileClose($file)
            ShellExecute("BezierData.txt")
        Case $ButPt1
            Do
                If _IsPressed("01") Then PtMAdj($aPts[2][0], $aPts[2][1])
                Sleep(10)
            Until 0
        Case $ButPt2
            Do
                If _IsPressed("01") Then PtMAdj($aPts[0][0], $aPts[0][1])
                Sleep(10)
            Until 0
        Case $ButPt3
            Do
                If _IsPressed("01") Then PtMAdj($aPts[1][0], $aPts[1][1])
                Sleep(10)
            Until 0
        Case $ButPt4
            Do
                If _IsPressed("01") Then PtMAdj($aPts[3][0], $aPts[3][1])
                Sleep(10)
            Until 0
        Case $ButAllPts ; Move all points
            Do
                If _IsPressed("01") Then
                    $aMPos = MouseGetPos()
                    $aTemp = $aPts
                    Do
                        $aMPosNew = MouseGetPos()
                        For $i = 0 To UBound($aPts) - 1
                            $aPts[$i][0] = $aTemp[$i][0] - ($aMPos[0] - $aMPosNew[0])
                            $aPts[$i][1] = $aTemp[$i][1] - ($aMPos[1] - $aMPosNew[1])
                        Next
                        Example()
                        Sleep(10)
                        If Not _IsPressed("01") Then ExitLoop 2
                    Until 0
                EndIf
                Sleep(10)
            Until 0
    EndSwitch
Until $msg = $GUI_EVENT_CLOSE

;Point position Adjusted by dragging Mouse around function.
Func PtMAdj(ByRef $XPt, ByRef $YPt)
    Local $x, $y, $aMPos, $aMPosNew
    $aMPos = MouseGetPos()
    $x = $XPt
    $y = $YPt
    Do
        $aMPosNew = MouseGetPos()
        $XPt = $x - ($aMPos[0] - $aMPosNew[0])
        $YPt = $y - ($aMPos[1] - $aMPosNew[1])
        Example()
        Sleep(10)
        If Not _IsPressed("01") Then ExitLoop 2
    Until 0
    Return
EndFunc ;==>PtMAdj

Func Example()
    GUICtrlDelete($a)
    $a = GUICtrlCreateGraphic(10, 10, 300, 300)
    If $bDispCtrlPts Then GUICtrlSetGraphic($a, $GUI_GR_HINT) ; display control point and end point of bezier/line curve.


    Switch $iFill
        Case 1
            GUICtrlSetGraphic($a, $GUI_GR_COLOR, 0xff0000, 0xffffff); No Fill
        Case 2
            GUICtrlSetGraphic($a, $GUI_GR_COLOR, 0xff0000, 0xff0000); Fill
    EndSwitch

    ;GUICtrlSetBkColor($a, 0xffffff) ; White background colour
    GUICtrlSetGraphic($a, $GUI_GR_PENSIZE, 3)
    GUICtrlSetGraphic($a, $GUI_GR_MOVE, $aPts[0][0], $aPts[0][1]) ; start point
    GUICtrlSetGraphic($a, $GUI_GR_BEZIER, $aPts[1][0], $aPts[1][1], $aPts[2][0], $aPts[2][1], $aPts[3][0], $aPts[3][1])

    GUICtrlSetGraphic($a, $GUI_GR_REFRESH) ; force refresh after dynamic update of graphics
    Return
EndFunc ;==>Example
Link to comment
Share on other sites

That's great!

(But wait a minute,... it's not so great. I could have saved myself some time by writing "How about some extra features?" instead of writing some code :mellow: )

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...