Guest User

Untitled

a guest
Jan 4th, 2026
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. def strange_move_to(target_x, target_y, duration=1.5):
  2.    
  3.     start_x, start_y = pyautogui.position()
  4.    
  5.     dist = math.hypot(target_x - start_x, target_y - start_y)
  6.    
  7.     # Random offset range based on distance (adjust for wilder curves)
  8.     offset_scale = dist * 0.5
  9.    
  10.     # Control Point 1: (This will be a curve controller)
  11.     p1_x = start_x + (target_x - start_x) * 0.3 + random.uniform(-offset_scale, offset_scale)
  12.     p1_y = start_y + (target_y - start_y) * 0.3 + random.uniform(-offset_scale, offset_scale)
  13.  
  14.     # Control Point 2
  15.     p2_x = start_x + (target_x - start_x) * 0.7 + random.uniform(-offset_scale, offset_scale)
  16.     p2_y = start_y + (target_y - start_y) * 0.7 + random.uniform(-offset_scale, offset_scale)
  17.  
  18.     steps = int(duration * 60) # You can tinker with this if you want. I am choosing 60 it/s since it looks more smooth and human. You may wanna alternate this with some more noise to make it even more realistic.
  19.    
  20.     for i in range(steps + 1):
  21.         t = i / steps # t goes from 0.0 to 1.0 (basically a parametric equation)
  22.        
  23.         # Cubic Bezier Formula:
  24.         # B(t) = (1-t)^3*P0 + 3(1-t)^2*t*P1 + 3(1-t)*t^2*P2 + t^3*P3
  25.        
  26.         # Base calculation
  27.         u = 1 - t
  28.         tt = t * t
  29.         uu = u * u
  30.         uuu = uu * u
  31.         ttt = tt * t
  32.        
  33.         bx = (uuu * start_x) + (3 * uu * t * p1_x) + (3 * u * tt * p2_x) + (ttt * target_x)
  34.         by = (uuu * start_y) + (3 * uu * t * p1_y) + (3 * u * tt * p2_y) + (ttt * target_y)
  35.        
  36.         noise_magnitude = 2 * (1 - t)
  37.         noise_x = random.gauss(0, noise_magnitude)
  38.         noise_y = random.gauss(0, noise_magnitude)
  39.        
  40.         final_x = bx + noise_x
  41.         final_y = by + noise_y
  42.        
  43.         pyautogui.moveTo(final_x, final_y, _pause=False)
  44.        
  45.         time.sleep(duration / steps)
  46.  
  47. # --- Example Usage ---
  48. if __name__ == "__main__":
  49.     strange_move_to(500, 500, duration=2.0)
  50.     strange_move_to(100, 100, duration=1.0)
Advertisement
Add Comment
Please, Sign In to add comment