RandomBezier help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
KramtauDesra
Posts: 23
Joined: 04 Jul 2021, 17:15

RandomBezier help

27 Jul 2021, 04:51

Hello everyone, so I stumbled upon this ahk command called "RandomBezier", it seemed really helpful, but I just could not find anything on how exactly to use it? I've seen some examples of it, but like I can't find anything on what stuff like "T" time A_Space "P3-5" means in it, if anyone could explain it to me, I would be very helpful, thank you.
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: RandomBezier help

27 Jul 2021, 04:55

It's surely no AHK command - but some kind of user-defined function, and there might be different versions of it.
That's why you should link to where you found it - so that people can take a look at the code. Everything else will take a crystal ball, or at least additional work for potential helpers...
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: RandomBezier help

27 Jul 2021, 05:06

The github link there (https://github.com/MasterFocus/AutoHotkey/tree/master/Functions/RandomBezier) provides an example (and a "usage" file).
Did you try it ? It works for me.

About the T option:
https://github.com/MasterFocus/AutoHotkey/blob/master/Functions/RandomBezier/USAGE wrote:"Tx" (where x is a positive number)
> The time of the mouse movement, in miliseconds
> Defaults to 200 if not present
About the P option:
https://github.com/MasterFocus/AutoHotkey/blob/master/Functions/RandomBezier/USAGE wrote: # "Px" or "Py-z" (where x, y and z are positive numbers)
> "Px" uses exactly 'x' control points
> "Py-z" uses a random number of points (from 'y' to 'z', inclusive)
> Specifying 1 anywhere will be replaced by 2 instead
> Specifying a number greater than 19 anywhere will be replaced by 19
> Defaults to "P2-5"
KramtauDesra
Posts: 23
Joined: 04 Jul 2021, 17:15

Re: RandomBezier help

27 Jul 2021, 05:10

Oh, no I haven't, I checked them out and the files don't seem to talk about the "time" function, also this might be a stupid question, but how do I even get it so I can use it in my files?
KramtauDesra
Posts: 23
Joined: 04 Jul 2021, 17:15

Re: RandomBezier help

27 Jul 2021, 05:11

sorry for the reply with no time usage, it only showed for me that you explained it after I replied
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: RandomBezier help

27 Jul 2021, 05:12

You should start with the example, and try it - then play with it, and look at the 'Usage' file which explains the options.
KramtauDesra
Posts: 23
Joined: 04 Jul 2021, 17:15

Re: RandomBezier help

27 Jul 2021, 05:20

Yes, but didn't you mention this was like some kind of an addon or something? If it isn't in ahk originally, then somehow I need to get it I assume?
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: RandomBezier help

27 Jul 2021, 05:25

The file RandomBezier.ahk (https://github.com/MasterFocus/AutoHotkey/blob/master/Functions/RandomBezier/RandomBezier.ahk) contains the function:

Code: Select all

/*
    RandomBezier.ahk
    Copyright (C) 2012,2013 Antonio Fran�a

    This script is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This script is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this script.  If not, see <http://www.gnu.org/licenses/>.
*/

;========================================================================
; 
; Function:     RandomBezier
; Description:  Moves the mouse through a random B�zier path
; URL (+info):  --------------------
;
; Last Update:  30/May/2013 03:00h BRT
;
; Created by MasterFocus
; - https://github.com/MasterFocus
; - http://masterfocus.ahk4.net
; - http://autohotkey.com/community/viewtopic.php?f=2&t=88198
;
;========================================================================

RandomBezier( X0, Y0, Xf, Yf, O="" ) {
    Time := RegExMatch(O,"i)T(\d+)",M)&&(M1>0)? M1: 200
    RO := InStr(O,"RO",0) , RD := InStr(O,"RD",0)
    N:=!RegExMatch(O,"i)P(\d+)(-(\d+))?",M)||(M1<2)? 2: (M1>19)? 19: M1
    If ((M:=(M3!="")? ((M3<2)? 2: ((M3>19)? 19: M3)): ((M1=="")? 5: ""))!="")
        Random, N, %N%, %M%
    OfT:=RegExMatch(O,"i)OT(-?\d+)",M)? M1: 100, OfB:=RegExMatch(O,"i)OB(-?\d+)",M)? M1: 100
    OfL:=RegExMatch(O,"i)OL(-?\d+)",M)? M1: 100, OfR:=RegExMatch(O,"i)OR(-?\d+)",M)? M1: 100
    MouseGetPos, XM, YM
    If ( RO )
        X0 += XM, Y0 += YM
    If ( RD )
        Xf += XM, Yf += YM
    If ( X0 < Xf )
        sX := X0-OfL, bX := Xf+OfR
    Else
        sX := Xf-OfL, bX := X0+OfR
    If ( Y0 < Yf )
        sY := Y0-OfT, bY := Yf+OfB
    Else
        sY := Yf-OfT, bY := Y0+OfB
    Loop, % (--N)-1 {
        Random, X%A_Index%, %sX%, %bX%
        Random, Y%A_Index%, %sY%, %bY%
    }
    X%N% := Xf, Y%N% := Yf, E := ( I := A_TickCount ) + Time
    While ( A_TickCount < E ) {
        U := 1 - (T := (A_TickCount-I)/Time)
        Loop, % N + 1 + (X := Y := 0) {
            Loop, % Idx := A_Index - (F1 := F2 := F3 := 1)
                F2 *= A_Index, F1 *= A_Index
            Loop, % D := N-Idx
                F3 *= A_Index, F1 *= A_Index+Idx
            M:=(F1/(F2*F3))*((T+0.000001)**Idx)*((U-0.000001)**D), X+=M*X%Idx%, Y+=M*Y%Idx%
        }
        MouseMove, %X%, %Y%, 0
        Sleep, 1
    }
    MouseMove, X%N%, Y%N%, 0
    Return N+1
}
You can copy it into your own files - or save it as a separate ahk-file and then #include it in your main script file (like the github example does):

Code: Select all

; 30/May/2013 03:00h BRT

#Include RandomBezier.ahk

F5:: ToolTip, % "Points: " RandomBezier( 0, 0, 400, 400, "T500 RO RD OT0 OB0 OL0 OR0 P4-20" )
F6:: ToolTip, % "Points: " RandomBezier( 0, 0, 200, 200, "T1000 RO RD")
F7:: ToolTip, % "Points: " RandomBezier( 0, 0, 150, 150, "T1500 RO RD OT150 OB150 OL150 OR150 P6-4" )
F8:: ToolTip, % "Points: " RandomBezier( 0, 0, 200, 0, "T1200 RO RD OT100 OB-100 OL0 OR0 P4-3" )

F9:: ToolTip, % "Points: " RandomBezier( 0, 0, 400, 300, "T1000 RO P5" )
F10:: ToolTip, % "Points: " RandomBezier( 400, 300, 0, 0, "T1000 RD" )

F12::RELOAD
ESC::EXITAPP
Then you can call the function like shown above. Of course, you can remove the Tooltip part, if you don't need/want it:

Code: Select all

RandomBezier( 0, 0, 200, 200, "T1000 RO RD")
KramtauDesra
Posts: 23
Joined: 04 Jul 2021, 17:15

Re: RandomBezier help

27 Jul 2021, 05:31

Thank you so much
KramtauDesra
Posts: 23
Joined: 04 Jul 2021, 17:15

Re: RandomBezier help

27 Jul 2021, 05:49

Hello, me again, sorry for bothering, but I seem to get this error while trying to include it, am I suppost to have it in a specific location? #Include file RandomBezier.ahk cannot be opened
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: RandomBezier help

27 Jul 2021, 05:54

Easiest way is to save RandomBezier.ahk in the same directory like your main script, then #Include RandomBezier.ahk .
Or you add a path (see https://www.autohotkey.com/docs/commands/_Include.htm)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mapcarter, Marium0505 and 384 guests