souldjer777 Posted July 25, 2019 Posted July 25, 2019 (edited) Good Morning All, I have - in my opinion - a very strange and difficult situation - been up since 3 AM so that doesn't help either lol. I would like to do a randomized mouseclick within an elliptical area. I would need different x, y coordinates returned within this given elliptical area. How could I possibly do this in AutoIT? My brain is melting from just the thought now - been working on this for hours... I don't ask for help unless I can't figure it out myself. Thanks in advance! Much appreciated - I really need to get this figured out - Any examples would be appreciated! Fill an ellipse with random dots Edited July 25, 2019 by souldjer777 "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
souldjer777 Posted July 25, 2019 Author Posted July 25, 2019 Believe I may be on to something here... just too burned out to get it straight. Algorithm: Calculate pseudo-random point inside an ellipse "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
souldjer777 Posted July 25, 2019 Author Posted July 25, 2019 Believe I got it... expandcollapse popup#include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> ;Mouse Click Randomized Within An Eliptical Area ;Got the calculations from here: ;https://stackoverflow.com/questions/5529148/algorithm-calculate-pseudo-random-point-inside-an-ellipse ;Algorithm: Calculate pseudo-random point inside an ellipse ;Generate a random point inside a circle of radius 1. This can be done by taking a random angle phi in the interval [0, 2*pi) and a random value rho in the interval [0, 1) and compute ;x = sqrt(rho) * cos(phi) ;y = sqrt(rho) * sin(phi) ;The square root in the formula ensures a uniform distribution inside the circle. ;Scale x and y to the dimensions of the ellipse ;x = x * width/2.0 ;y = y * height/2.0 ;If you do decide to troll, please exit planet. ; Center of screen coordinates Local $i_Xcenter01 = @DesktopWidth / 2 Local $i_Ycenter01 = @DesktopHeight / 2 Local $s_Program_Title01 = "Random mouse click within an elliptical area" MsgBox (0, $s_Program_Title01, $s_Program_Title01 & @CRLF & @CRLF & 'NOTE: Press "ESC" button to exit application' & _ @CRLF & @CRLF & "Screen Center: X = " & $i_Xcenter01 & @CRLF & "Screen Center: Y = " & $i_Ycenter01 & @CRLF & @CRLF ) ; Test is done on a Window where the Window Title contains the text "blank_white_canvas" ; Opt("WinTitleMatchMode",2) - Option 2 will match any substring in the title ; I used a large white canvas in Gimp while already having selected the pencil tool in black color. Opt("WinTitleMatchMode",2) Local $s_WinTitle01 = "blank_white_canvas" ; Set the Escape hotkey to terminate the script. HotKeySet("{ESC}", "_Terminate") Winactivate ($s_WinTitle01) If @error Then MsgBox(0, $s_Program_Title01, 'Winactivate - ' & $s_WinTitle01 & ' ERROR: ' & @error ) _Terminate() EndIf ; Assign a Local constant variable the approximate PI number. Local Const $f_PIE01 = 3.141592653589793 Local $i_Count01 While 1 $i_Count01 =+ 1 ; Assign random values to x and y within the elipse ; $f_PHI_01 is a random angle $f_PHI_01 = Random(0, 2*$f_PIE01) ; $f_RHO_01 is a random value from 0 to 1 $f_RHO_01 = Random (0, 1) ;1 Take a random angle $f_x01 = sqrt($f_RHO_01 ) * cos($f_PHI_01 ) $f_y01 = sqrt($f_RHO_01 ) * sin($f_PHI_01 ) ;2 Scale x and y to the dimensions of the ellipse ; 80 is the width in pixels and 50 is the height in pixels $f_x01 = $f_x01 * 80/2.0 $f_y01 = $f_y01 * 50/2.0 ; Add the x and y corrdinates to the returned x and y center of the screen. MouseClick($MOUSE_CLICK_LEFT, $i_Xcenter01 + $f_x01, $i_Ycenter01 + $f_y01 ) ConsoleWrite('Line: ' & @ScriptLineNumber & ' Loop: ' & $i_Count01 & ' X,Y: ' & $i_Xcenter01 + $f_x01 & ',' & $i_Ycenter01 + $f_y01 & ' ERROR: ' & @error & @CRLF) If @error Then ConsoleWrite('Line: ' & @ScriptLineNumber & ' Loop: ' & $i_Count01 & ' MouseClick - $MOUSE_CLICK_LEFT ERROR: ' & @error & @CRLF) MsgBox(0, $s_Program_Title01, 'MouseClick - $MOUSE_CLICK_LEFT ERROR: ' & @error ) _Terminate() EndIf ; Wait half a second Sleep (500) WEnd Func _Terminate() Exit EndFunc ;==>_Terminate ; Hard Exit Exit "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
Malkey Posted July 25, 2019 Posted July 25, 2019 I imagine random dots found to be inside an ellipse using the function, _PointInEllipse() from the example from here, would work.
souldjer777 Posted July 25, 2019 Author Posted July 25, 2019 Thank you Malkey! Darnit, yeah... I thought someone had already done this lol. "Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"Song Title: I guess you could sayArtist: Middle Class Rut
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now