I'm completely new to programming and python as a whole but I have recently joined a class. Currently I am trying to make a program which prompts the user for an input of the coordinates of the center of an object on the screen.
The program will then take the X and Y coordinates of the item and randomize the coordinates within a range of +- 15. So if the X coordinate is 30, the program will pick a random number of 15 to 45.
Then the program will take a random delay between 3.2 to 4.3 seconds and move the mouse from it's current position to the randomized coordinates within the random time delay.
I want it to be able to loop endlessly until I prompt it to stop, and I think I can figure that out. However, I do not understand how to properly use parameters to allow the local variables coords_x , coords_y and click_delay to be used in the function main()
Here is what I have so far:
#! python3
import pyautogui, sys
import random
from random import randint
center_x = int(input("Please enter the X coordinate of the center of the item:"))
center_y = int(input("Please enter the Y coordinate of the center of the item:"))
#y = 23 long 735 - 712
#x = 23 862 - 838
buffer = 17
def randomizex():
min_x = center_x - buffer
max_x = center_x + buffer
coords_x = randint(min_x, max_x)
def randomizey():
min_y = center_y - buffer
max_y = center_y + buffer
coords_y = randint(min_y, max_y)
def randomizedelay():
click_delay = random.uniform(3.2, 4.3)
def main():
randomizex()
randomizey()
randomizedelay()
pyautogui.moveTo(coords_x, coords_y, click_delay)
main()
I appreciate any help. The other answers I have found to questions like these are rather confusing to a newbie and some of them are for python 2.