PyAutoGUI的Tween / Easing功能



简 介:本文简要介绍PyAutoGUI的 Tween / Easing 功能。

关键词 PyAutoGUIPythonTween / Easing

§01 能说明


  Tween / Easing 功能可指示鼠标移动到目的地时的进度。通常在一段时间内移动鼠标时,鼠标会以恒定的速度沿直线直接移动到目的地。这被称为线性补间或线性缓动函数。

  PyAutoGUI 在 pyautogui 模块中有其他可用的 Tween 功能。可以将 pyautogui.easeInQuadpyautogui.easeOutQuadpyautogui.easeOutElastic 等函数作为第 4 个参数传递给 moveTo()move()dragTo()drag() 函数,以使鼠标光标以下述状态移动,但总持续时间仍然与传递给函数的参数相同。

参数功能
pyautogui.easeInQuad开始缓慢移动,接近目的地时变快。
pyautogui.easeOutQuad开始快速移动,接近目的地时变慢。
pyautogui.easeInOutQuad开始和结束时快速移动, 中间时速度变慢。
pyautogui.easeInBounce橡皮筋 一样小幅度来回摆动,直到在目的地停顿下来
pyautogui.easeOutElastic橡皮筋 一样大幅度来回摆动,直到在目的地停顿下来

§02 例演示


>>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInQuad)     # 开始缓慢移动,接近目的地时变快
>>> pyautogui.moveTo(100, 100, 2, pyautogui.easeOutQuad)    # 开始快速移动,接近目的地时变慢
>>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInOutQuad)  # 开始和结束时快速移动, 中间时速度变慢
>>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInBounce)   # 像 `橡皮筋` 一样小幅度来回摆动,直到在目的地停顿下来
>>> pyautogui.moveTo(100, 100, 2, pyautogui.easeInElastic)  # 像 `橡皮筋` 一样大幅度来回摆动,直到在目的地停顿下来

一步了解


如果你想进一步了解此功能,可以查看下述说明:

These tweening functions are copied from Al Sweigart’s PyTweening module: https://pypi.python.org/pypi/PyTweening https://github.com/asweigart/pytweening This module does not have to be installed to use the tweening functions.

If you want to create your own tweening function, define a function that takes a single float argument between 0.0 (representing the start of the mouse travelling) and 1.0 (representing the end of the mouse travelling) and returns a float value between 0.0 and 1.0.


相关文章:

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_43964993

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值