@Sanger

Как уменьшить время прохождения кривой?

import numpy
import pyautogui
import random
import scipy
import time
from scipy import interpolate
# Any duration less than this is rounded to 0.0 to instantly move the mouse.
pyautogui.MINIMUM_DURATION = 0  # Default: 0.1
# Minimal number of seconds to sleep between mouse moves.
pyautogui.MINIMUM_SLEEP = 0  # Default: 0.05
# The number of seconds to pause after EVERY public function call.
pyautogui.PAUSE = 0  # Default: 0.1


cp = random.randint(3, 5)  # Number of control points. Must be at least 2.
x1, y1 = pyautogui.position(497, 201)  # Starting position
x2, y2 = (random.randint(1302, 1415), random.randint(388, 419))  # Destination

# Distribute control points between start and destination evenly.
x = numpy.linspace(x1, x2, num=cp, dtype='int')
y = numpy.linspace(y1, y2, num=cp, dtype='int')
# Randomise inner points a bit (+-RND at most).
RND = random.randint(10,200)
print(RND)
xr = scipy.random.randint(-RND, RND, size=cp)
yr = scipy.random.randint(-RND, RND, size=cp)
xr[0] = yr[0] = xr[-1] = yr[-1] = 0
x += xr
y += yr

# Approximate using Bezier spline.
degree = 3 if cp > 3 else cp - 1  # Degree of b-spline. 3 is recommended.
                                  # Must be less than number of control points.
tck, u = scipy.interpolate.splprep([x, y], k=degree)
u = numpy.linspace(0, 1, num=max(pyautogui.size()))
points = scipy.interpolate.splev(u, tck)
print(points)

# Move mouse.

duration = 0.2
timeout = duration / len(points[0])
print(timeout)
for point in zip(*(i.astype(int) for i in points)):
    pyautogui.moveTo(*point)
    time.sleep(timeout)

вот измененный мной код для построения и ведения курсора по случайно сгенереной кривой безье измененный он потому что код неизвестного человека с этой ссылки отказывался работать. https://ask-dev.ru/info/560845/pyautogui-mouse-mov... Внимание вопрос как сделать что бы курсор проходил по кривой за строго определенное время например за 0.2 секунды,какие бы параметры я не менял курсор или пролетает мгновенно или ползет как черепаха секунд 5.
  • Вопрос задан
  • 85 просмотров
Пригласить эксперта
Ответы на вопрос 1
Vindicar
@Vindicar
RTFM!
1. Определи длину points через свойство shape.
2. Раздели общий интервал на длину points.
3. Полученное значение используй в time.sleep().
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы