-
Notifications
You must be signed in to change notification settings - Fork 6
/
quad.go
50 lines (38 loc) · 1.14 KB
/
quad.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
package easing
// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
// QuadIn accelerating from zero velocity
// https://easings.net/#easeInQuad
func QuadIn(t, b, c, d float64) float64 {
if t > d {
return c
}
t /= d
return c*t*t + b
}
// QuadOut decelerating to zero velocity
// https://easings.net/#easeOutQuad
func QuadOut(t, b, c, d float64) float64 {
if t > d {
return c
}
t /= d
return -c*t*(t-2) + b
}
// QuadInOut acceleration until halfway, then deceleration
// https://easings.net/#easeInOutQuad
func QuadInOut(t, b, c, d float64) float64 {
if t > d {
return c
}
t /= d / 2
if t < 1 {
return c/2*t*t + b
}
t--
return -c/2*(t*(t-2)-1) + b
}