Fabric.js easeInQuart()方法

Fabric.js easeInQuart()方法

在游戏或动画中,有许多移动的对象可以线性地从点A移动到点B,但在应用缓动或缓动函数后,可以使其看起来更加自然。缓动函数描述了动画的进展方式。通过这种方式,直线运动可以呈现出有趣的形状。

缓动函数 指定了参数随时间的变化速率。它的方程使得某物在开始时慢慢移动并加速,或在接近结束时减速。最常见的一组缓动方程来自Robert Penner的书籍和网页。

easeInQuart()方法 用于对象上的四次缓动效果。

语法:

easeInQuart(t, b, c, d)

参数: 该方法接受上述提及并以下所描述的四个参数:

  • t: 该参数保存动画开始时指定的时间。例如,如果t的值为0,则表示动画刚刚开始。
  • b: 该参数保存对象在x轴上的指定起始位置。例如,如果b的值为10,则表示对象在x坐标上的起始位置为10。
  • c: 该参数保存对象的指定值变化量。例如,如果c的值为30,则表示对象要向右移动30个单位,最终停在40。
  • d: 该参数保存整个过程的指定持续时间。例如,如果d的值为2,则表示对象有2秒的时间将这个运动从10到40完成。

返回值: 该方法返回对象的缓动位置,即指定时间的对象位置。

示例1:

<html> 
<head> 
  <!-- Adding the FabricJS library -->
  <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"> 
  </script> 
</head> 
<body> 
<script type="text/javascript"> 
  
   // The easeInQuart() function 
   function easeInQuart (t, b, c, d) { 
      return c * (t /= d) * 
        t * t * t + b; 
   } 
  
   // Calling the easeInQuart() function 
   // over the specified parameter values 
   console.log( 
     fabric.util.ease.easeInQuart(1, 2, 3, 4) 
   );  
</script> 
</body> 
</html>

输出:

2.01171875

示例2:

<html> 
<head> 
  <!-- Adding the FabricJS library -->
  <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"> 
  </script> 
</head> 
<body> 
<script type="text/javascript"> 
    
   // Initializing the parameters with 
  // its values 
   var t = 5; 
   var b = 10; 
   var c = 40; 
   var d = 12; 
  
   // Calling the easeInQuart() function 
   // over the specified parameter values 
   console.log( 
     fabric.util.ease.easeInQuart(t, b, c, d) 
   );  
</script> 
</body> 
</html>

输出:

11.205632716049383

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程