Open In App

Fabric.js easeInBack() Method

In gaming applications, there are many moving objects from point A to B in a linear fashion, but after applying an easing, it can make it look more natural. An easing function tells the animation about its progress. A straight motion can take an interesting shape.

Easing functions are the functions that control the speed of animation or specify the rate of change of a parameter over time to finally give some desired effect. The equations result in moving slowly at the start and speed up or slow down near the end. The most common set of easing equations come from Robert Penner’s webpage.



The easeInBack() method is used for backwards easing in.

Syntax:



easeInBack(t, b, c, d)

Parameters: This method accepts four parameters as mentioned above and described below.

Return Value: This method returns the eased position of the object i.e., the position of the object at a specific time.

Example 1:




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
  // Initializing easeInBack() function
  function easeInBack (t, b, c, d) {
    if (s == undefined) s = 1.70158;
    return c * (t /= d) * t * ((s + 1) * t - s) + b;
  }
    
  // Calling the easeInBack() function over 
  // the specified parameter values
  console.log(fabric.util.ease.easeInBack(1, 2, 3, 4));
</script>
  
</body>
  
</html>

Output:

1.8075903125

Example 2:




<!DOCTYPE html>
<html>
  
<head>
  <!-- Adding the FabricJS library -->
  <script src=
  </script>
</head>
  
<body>
<script type="text/javascript">
  
  // Initializing easeInBack() function
  function easeInBack (t, b, c, d) {
    if (s == undefined) s = 1.70158;
    return c * (t /= d) * t * ((s + 1) * t - s) + b;
  }
    
  // Initializing the parameters with its values
  var t = 5;
  var b = 10;
  var c = 40;
  var d = 12;
    
  // Calling the easeInBack() function over 
  // the specified parameter values
  console.log(fabric.util.ease.easeInBack(t, b, c, d));
</script>
  
</body>
  
</html>

Output:

6.000543981481481

Article Tags :