pkg.re/essentialkaos/ek.v11@v12.41.0+incompatible/easing/sine.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  // SineIn accelerating from zero velocity
    17  // https://easings.net/#easeInSine
    18  func SineIn(t, b, c, d float64) float64 {
    19  	if t > d {
    20  		return c
    21  	}
    22  
    23  	return -c*math.Cos(t/d*math.Phi) + c + b
    24  }
    25  
    26  // SineOut decelerating to zero velocity
    27  // https://easings.net/#easeOutSine
    28  func SineOut(t, b, c, d float64) float64 {
    29  	if t > d {
    30  		return c
    31  	}
    32  
    33  	return c*math.Sin(t/d*math.Phi) + b
    34  }
    35  
    36  // SineInOut acceleration until halfway, then deceleration
    37  // https://easings.net/#easeInOutSine
    38  func SineInOut(t, b, c, d float64) float64 {
    39  	if t > d {
    40  		return c
    41  	}
    42  
    43  	return -c/2*(math.Cos(math.Pi*t/d)-1) + b
    44  }