Fabric.js easeInCubic()方法

Fabric.js easeInCubic()方法

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

缓动函数 描述了参数随时间变化的速率。它的方程使得某种东西在开始时慢慢移动,并在接近结束时加速或减速。请参考罗伯特·佩纳的书籍和网页以了解缓动函数。

easeInCubic()方法 此方法用于立方缓动进入。此函数的曲线开始缓慢,结束迅速。

语法:

easeInCubic(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:

<!DOCTYPE html> 
<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 easeInCubic() function 
 function easeInCubic (t, b, c, d) { 
    return c * (t /= d) * t * t + b; 
} 
  
 // Calling the easeInCubic() function over 
 // the specified parameter values 
 console.log(fabric.util.ease.easeInCubic(1, 2, 3, 4));  
</script> 
  
</body> 
  
</html>

输出:

2.046875

示例2:

<!DOCTYPE html> 
<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 easeInCubic() function 
 function easeInCubic (t, b, c, d) { 
    return c * (t /= d) * t * t + b; 
 } 
  
 // Initializing the parameters with its values 
 var t = 5; 
 var b = 10; 
 var c = 40; 
 var d = 12; 
  
 // Calling the easeInCubic() function over 
 // the specified parameter values 
 console.log(fabric.util.ease.easeInCubic(t, b, c, d));  
</script> 
  
</body> 
  
</html>

输出:

12.893518518518519

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程