pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/easing/circ.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  // CircIn accelerating from zero velocity
    17  // https://easings.net/#easeInCirc
    18  func CircIn(t, b, c, d float64) float64 {
    19  	if t > d {
    20  		return c
    21  	}
    22  
    23  	t /= d
    24  
    25  	return -c*(math.Sqrt(1-t*t)-1) + b
    26  }
    27  
    28  // CircOut decelerating to zero velocity
    29  // https://easings.net/#easeOutCirc
    30  func CircOut(t, b, c, d float64) float64 {
    31  	if t > d {
    32  		return c
    33  	}
    34  
    35  	t /= d
    36  	t--
    37  
    38  	return c*math.Sqrt(1-t*t) + b
    39  }
    40  
    41  // CircInOut acceleration until halfway, then deceleration
    42  // https://easings.net/#easeInOutCirc
    43  func CircInOut(t, b, c, d float64) float64 {
    44  	if t > d {
    45  		return c
    46  	}
    47  
    48  	t /= d / 2
    49  
    50  	if t < 1 {
    51  		return -c/2*(math.Sqrt(1-t*t)-1) + b
    52  	}
    53  
    54  	t -= 2
    55  
    56  	return c/2*(math.Sqrt(1-t*t)+1) + b
    57  }