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