drawn with ms paint' different brushes the distance variable starts at so on the first iteration of the while loopthe first drag(call drags the cursor pixels to the righttaking seconds distance is then decreased to xand the second drag(call drags the cursor pixels down the third drag(call drags the cursor - horizontally ( to the leftzdistance is decreased to and the last drag(call drags the cursor pixels up on each iterationthe mouse is dragged rightdownleftand upand distance is slightly smaller than it was in the previous iteration by looping over this codeyou can move the mouse cursor to draw square spiral you could draw this spiral by hand (or ratherby mouse)but you' have to work slowly to be so precise pyautogui can do it in few secondsnote at the time of this writingpyautogui can' send mouse clicks or keystrokes to certain programssuch as antivirus software (to prevent viruses from disabling the softwareor video games on windows (which use different method of receiving mouse and keyboard inputyou can check the online documentation at readthedocs ioto see if these features have been added scrolling the mouse the final pyautogui mouse function is scroll()which you pass an integer argument for how many units you want to scroll the mouse up or down the size of unit varies for each operating system and applicationso you'll have to experiment to see exactly how far it scrolls in your particular situation