Spiral drawing script how to make it run from current mouse coordinates?

Get help with using AutoHotkey and its commands and hotkeys
NackJich
Posts: 22
Joined: 30 Jul 2017, 06:34

Spiral drawing script how to make it run from current mouse coordinates?

18 Oct 2018, 16:13

Code: Select all

F12:: MoveMouse_Spiral(800, 450, 20, 36, 6) ; 36 steps per arm, 6 arms


;-------------------------------------------------------------------------------
MoveMouse_Spiral(cx, cy, r, s, a) { ; move mouse in a spiral
;-------------------------------------------------------------------------------
    ; cx, cy = center coordinates
    ; r = radius
    ; s = number of steps
    ; a = number of spiral arms
    ;---------------------------------------------------------------------------
    CoordMode, Mouse, Screen
    $Pi := 4 * ATan(1)
    MouseClick, Left, cx, cy,, 0
    Loop, % s * a
        MouseClick, Left
            , cx + r * Cos(A_Index * 2 * $Pi / s) * A_Index / s
            , cy + r * Sin(A_Index * 2 * $Pi / s) * A_Index / s
            ,, 0
}
Hi this code was posted a few years ago by wolf_II. I confess to being a complete beginner. How would it be possible to modify this to make it run from the current mouse coordinates? It works fine as it is but always starts from a fixed point on the screen. Thank you!
swagfag
Posts: 2838
Joined: 11 Jan 2017, 17:59

Re: Spiral drawing script how to make it run from current mouse coordinates?

18 Oct 2018, 16:39

Code: Select all

CoordMode, Mouse, Screen

F12::
    MouseGetPos x, y
    MoveMouse_Spiral(x, y, 20, 36, 6) ; 36 steps per arm, 6 arms
Return

;-------------------------------------------------------------------------------
MoveMouse_Spiral(cx, cy, r, s, a) { ; move mouse in a spiral
;-------------------------------------------------------------------------------
    ; cx, cy = center coordinates
    ; r = radius
    ; s = number of steps
    ; a = number of spiral arms
    ;---------------------------------------------------------------------------
    $Pi := 4 * ATan(1)
    MouseClick, Left, cx, cy,, 0
    Loop, % s * a
        MouseClick, Left
            , cx + r * Cos(A_Index * 2 * $Pi / s) * A_Index / s
            , cy + r * Sin(A_Index * 2 * $Pi / s) * A_Index / s
            ,, 0
}
NackJich
Posts: 22
Joined: 30 Jul 2017, 06:34

Re: Spiral drawing script how to make it run from current mouse coordinates?

19 Oct 2018, 15:02

Thanks Swagfag. How would it be possible to get the mouse to move in the same spiral but without clicking?
Noo0B
Posts: 73
Joined: 26 Jan 2018, 19:54

Re: Spiral drawing script how to make it run from current mouse coordinates?

19 Oct 2018, 15:20

Just change
MouseClick, left
to
MouseMove
Cheers.
NackJich
Posts: 22
Joined: 30 Jul 2017, 06:34

Re: Spiral drawing script how to make it run from current mouse coordinates?

21 Oct 2018, 16:21

Code: Select all

CoordMode, Mouse, Screen
#SingleInstance Force
Sleep 1000 ; ms
;KeyWait, LButton, D

MouseGetPos x, y
    MoveMouse_Spiral(x, y, 20, 36, 6) ; 36 steps per arm, 6 arms

MoveMouse_Spiral(cx, cy, r, s, a) { ; move mouse in a spiral
;-----------------------------------------------------------------------------
;----------------------------------------------------------------------------
    ; cx, cy = center coordinates    ; s = number of steps

    ; r = radius---
    ; a = number of spiral arms
    ;---------------------------------------------------------------------------
    $Pi := 4 * ATan(1)
    MouseClick, Left, cx, cy,, 0
    click Down
    Loop, % s * a
        
        MouseMove
        
            , cx + r * Cos(A_Index * 2 * $Pi / s) * A_Index / s
            , cy + r * Sin(A_Index * 2 * $Pi / s) * A_Index / s
            Sleep 500 ; ms
            ,, 0
            Sleep 500 ; ms
            
}
click Up
esc::exitapp
I have a working version which moves the mouse in a spiral without clicking. I'm trying to get it to click at the start and release at the end and so draw in my app. Where do I have to put my click down and click up to achieve this? Thanks. The above code makes the spiral but not the drawing!
Noo0B
Posts: 73
Joined: 26 Jan 2018, 19:54

Re: Spiral drawing script how to make it run from current mouse coordinates?

22 Oct 2018, 10:05

Hi,
You may want to try this:

Code: Select all

#SingleInstance Force
CoordMode, Mouse
SetFormat, Float, 0.7
$Pi := 4 * ATan(1)
Radius:= 20
Sides:= 3
CenterOffset:= 3 ; Swapping sin to cos and vice versa below toggles the Offset vertical to horizontal and the rotation direction. If negative values are used here here the direction is inward, and it must be larger or equal to Cycles.
	If (CenterOffset!= 0) {
		IndexOffset:= 1
			If (CenterOffset = 1)
				OffsetFactor:= (1/((Sides/2) + CenterOffset * CenterOffset))
			Else
				OffsetFactor:= (1/((Sides/CenterOffset) + CenterOffset * CenterOffset))
	} Else {
		OffsetFactor:= 0
		IndexOffset:= 0
	}
Cycles:= 17 + OffsetFactor
;Cycles:= 17 + 1/Sides ; if Sides is too small and the last drawn cycle is incomplete, change to this line
LoopCount:= Sides * Cycles

F2::
	MouseGetPos x, y
	Loop, %LoopCount% {
		n:= A_Index - IndexOffset
		StepVectorFactor:= n * 2 * $Pi / Sides ; - here swaps rotation direction
		StepLenghtFactor:= CenterOffset +  n / Sides
		Step_x:= x - Radius * Sin(StepVectorFactor) * StepLenghtFactor ; + or - here defines the inital direction and swaps rotation direction
		Step_y:=  y - Radius * Cos(StepVectorFactor) * StepLenghtFactor ; + or - here defines the inital direction and swaps rotation direction
			If (N = 0)
				MouseMove, Step_x, Step_y, 0
			else {
				Click Down
				MouseMove, Step_x, Step_y, 0
			}
	}
	click Up
Return

esc::exitapp
Regards
NackJich
Posts: 22
Joined: 30 Jul 2017, 06:34

Re: Spiral drawing script how to make it run from current mouse coordinates?

22 Oct 2018, 15:30

Wow that IS impressive. It draws a three sided triangular spiral in Photoshop, and it draws it fast! Amazing thanks.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], ethanross1a, flyingDman and 156 guests