pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/easing/cubic.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 // CubicIn accelerating from zero velocity 11 // https://easings.net/#easeInCubic 12 func CubicIn(t, b, c, d float64) float64 { 13 if t > d { 14 return c 15 } 16 17 t /= d 18 19 return c*t*t*t + b 20 } 21 22 // CubicOut decelerating to zero velocity 23 // https://easings.net/#easeOutCubic 24 func CubicOut(t, b, c, d float64) float64 { 25 if t > d { 26 return c 27 } 28 29 t /= d 30 t-- 31 32 return c*(t*t*t+1) + b 33 } 34 35 // CubicInOut acceleration until halfway, then deceleration 36 // https://easings.net/#easeInOutCubic 37 func CubicInOut(t, b, c, d float64) float64 { 38 if t > d { 39 return c 40 } 41 42 t /= d / 2 43 44 if t < 1 { 45 return c/2*t*t*t + b 46 } 47 48 t -= 2 49 50 return c/2*(t*t*t+2) + b 51 }