-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pow.go
41 lines (33 loc) · 759 Bytes
/
pow.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
package curves
import (
"math"
"github.com/EliCDavis/polyform/math/sample"
)
func clamp(t, min, max float64) float64 {
return math.Max(min, math.Min(t, max))
}
func clamp01(t float64) float64 {
return clamp(t, 0, 1)
}
func PowerIn(power int) sample.FloatToFloat {
return func(f float64) float64 {
t := clamp01(f)
return math.Pow(t, float64(power))
}
}
func PowerOut(power int) sample.FloatToFloat {
return func(f float64) float64 {
t := 1.0 - clamp01(f)
return 1.0 - math.Pow(t, float64(power))
}
}
func PowerInOut(power int) sample.FloatToFloat {
return func(f float64) float64 {
t := clamp01(f)
if t < 0.5 {
return math.Pow(t*2, float64(power)) * 0.5
} else {
return 1.0 - math.Pow((1-t)*2, float64(power))*0.5
}
}
}