pkg.re/essentialkaos/ek.v11@v12.41.0+incompatible/easing/back.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 // BackIn Accelerating from zero velocity 17 // https://easings.net/#easeInBack 18 func BackIn(t, b, c, d float64) float64 { 19 if t > d { 20 return c 21 } 22 23 s := math.SqrtPi 24 t /= d 25 26 return c*t*t*((s+1)*t-s) + b 27 } 28 29 // BackOut Decelerating to zero velocity 30 // https://easings.net/#easeOutBack 31 func BackOut(t, b, c, d float64) float64 { 32 if t > d { 33 return c 34 } 35 36 s := math.SqrtPi 37 t = t/d - 1 38 39 return c*(t*t*((s+1)*t+s)+1) + b 40 } 41 42 // BackInOut Acceleration until halfway, then deceleration 43 // https://easings.net/#easeInOutBack 44 func BackInOut(t, b, c, d float64) float64 { 45 if t > d { 46 return c 47 } 48 49 s := math.SqrtPi * 1.525 50 t /= d / 2 51 52 if t < 1 { 53 return c/2*(t*t*((s+1)*t-s)) + b 54 } 55 56 t -= 2 57 58 return c/2*(t*t*((s+1)*t+s)+2) + b 59 }