Page 1 of 1

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

Posted: 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
; 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!

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

Posted: 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
; 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
}``````

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

Posted: 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?

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

Posted: 19 Oct 2018, 15:20
Just change
MouseClick, left
to
MouseMove
Cheers.

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

Posted: 19 Oct 2018, 15:37
Wonderful Thanks

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

Posted: 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

; 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!

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

Posted: 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)
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

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

Posted: 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.