pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/easing/expo.go (about)

     1  package easing
     2  
     3  // ////////////////////////////////////////////////////////////////////////////////// //
     4  //                                                                                    //
     5  //                         Copyright (c) 2022 ESSENTIAL KAOS                          //
     6  //      Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>     //
     7  //                                                                                    //
     8  // ////////////////////////////////////////////////////////////////////////////////// //
     9  
    10  import (
    11  	"math"
    12  )
    13  
    14  // ////////////////////////////////////////////////////////////////////////////////// //
    15  
    16  // ExpoIn accelerating from zero velocity
    17  // https://easings.net/#easeInExpo
    18  func ExpoIn(t, b, c, d float64) float64 {
    19  	if t > d {
    20  		return c
    21  	}
    22  
    23  	return c*math.Pow(2, 10*(t/d-1)) + b
    24  }
    25  
    26  // ExpoOut decelerating to zero velocity
    27  // https://easings.net/#easeOutExpo
    28  func ExpoOut(t, b, c, d float64) float64 {
    29  	if t > d {
    30  		return c
    31  	}
    32  
    33  	return c*(-math.Pow(2, -10*t/d)+1) + b
    34  }
    35  
    36  // ExpoInOut acceleration until halfway, then deceleration
    37  // https://easings.net/#easeInOutExpo
    38  func ExpoInOut(t, b, c, d float64) float64 {
    39  	if t > d {
    40  		return c
    41  	}
    42  
    43  	t /= d / 2
    44  
    45  	if t < 1 {
    46  		return c/2*math.Pow(2, 10*(t-1)) + b
    47  	}
    48  
    49  	t--
    50  
    51  	return c/2*(-math.Pow(2, -10*t)+2) + b
    52  }