三、机器模拟人工滑动轨迹 1、思路 ·滑块移动轨迹 · 机器模拟人工滑动轨迹 2、实践方法
封装:
def sliding_track(self, distance):
"""第三步:机器模拟人工滑动轨迹"""
# 按住按钮
self.click_and_hold(loc.verifyButton_loc)
# 获取轨迹
track = self.get_track(distance)
print(f"获取轨迹:{track}")
print("++++++++++++++++++++++++++++++++++++++++++++")
for t in track:
self.move_by_offset(t)
self.move_by_offset(5)
self.move_by_offset(-5)
# 松开按钮
self.release()
def get_track(self, distance):
"""在第三步里:滑块移动轨迹"""
track = []
current = 0
# 阈值
mid = distance * 3 / 4
t = random.randint(5, 6) / 10
v = 0
while current < distance:
if current < mid:
a = 6
else:
a = -7
v0 = v
v = v0 + a * t
move = v0 * t + 3 / 4 * a * t * t
current += move
track.append(round(move))
return track