Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def strange_move_to(target_x, target_y, duration=1.5):
- start_x, start_y = pyautogui.position()
- dist = math.hypot(target_x - start_x, target_y - start_y)
- # Random offset range based on distance (adjust for wilder curves)
- offset_scale = dist * 0.5
- # Control Point 1: (This will be a curve controller)
- p1_x = start_x + (target_x - start_x) * 0.3 + random.uniform(-offset_scale, offset_scale)
- p1_y = start_y + (target_y - start_y) * 0.3 + random.uniform(-offset_scale, offset_scale)
- # Control Point 2
- p2_x = start_x + (target_x - start_x) * 0.7 + random.uniform(-offset_scale, offset_scale)
- p2_y = start_y + (target_y - start_y) * 0.7 + random.uniform(-offset_scale, offset_scale)
- 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.
- for i in range(steps + 1):
- t = i / steps # t goes from 0.0 to 1.0 (basically a parametric equation)
- # Cubic Bezier Formula:
- # B(t) = (1-t)^3*P0 + 3(1-t)^2*t*P1 + 3(1-t)*t^2*P2 + t^3*P3
- # Base calculation
- u = 1 - t
- tt = t * t
- uu = u * u
- uuu = uu * u
- ttt = tt * t
- bx = (uuu * start_x) + (3 * uu * t * p1_x) + (3 * u * tt * p2_x) + (ttt * target_x)
- by = (uuu * start_y) + (3 * uu * t * p1_y) + (3 * u * tt * p2_y) + (ttt * target_y)
- noise_magnitude = 2 * (1 - t)
- noise_x = random.gauss(0, noise_magnitude)
- noise_y = random.gauss(0, noise_magnitude)
- final_x = bx + noise_x
- final_y = by + noise_y
- pyautogui.moveTo(final_x, final_y, _pause=False)
- time.sleep(duration / steps)
- # --- Example Usage ---
- if __name__ == "__main__":
- strange_move_to(500, 500, duration=2.0)
- strange_move_to(100, 100, duration=1.0)
Advertisement
Add Comment
Please, Sign In to add comment