File tree 2 files changed +19
-8
lines changed 2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -456,12 +456,12 @@ export class SpringValue<T = any> extends AnimationValue<T> {
456
456
anim . config = config = { ...BASE_CONFIG , ...config }
457
457
}
458
458
459
- // When "speed" is provided, we derive "tension " and "friction" from it .
460
- if ( ! is . und ( config . speed ) ) {
461
- config . tension = Math . pow ( ( 2 * Math . PI ) / config . speed , 2 ) * config . mass
462
- // Note: We treat "friction" as the *damping ratio* instead of as its coefficient.
459
+ // Derive "tension" and "friction" from "frequency " and "damping" .
460
+ if ( ! is . und ( config . frequency ) ) {
461
+ const damping = is . und ( config . damping ) ? 1 : config . damping
462
+ config . tension = Math . pow ( config . frequency , 2 ) * config . mass
463
463
config . friction =
464
- ( 4 * Math . PI * config . friction * config . mass ) / config . speed
464
+ ( damping * Math . sqrt ( config . tension * config . mass ) ) / 0.5
465
465
}
466
466
467
467
// Cache the angular frequency in rad/ms
Original file line number Diff line number Diff line change @@ -53,11 +53,22 @@ export interface AnimationConfig {
53
53
*/
54
54
tension : number
55
55
/**
56
- * The frequency response.
56
+ * The natural frequency (in seconds), which dictates the number of bounces
57
+ * per second when no damping exists.
57
58
*
58
- * An alternative to `tension` that describes the speed of an undamped spring.
59
+ * When defined, `tension` is derived from this, and `friction` is derived
60
+ * from `tension` and `damping`.
59
61
*/
60
- speed ?: number
62
+ frequency ?: number
63
+ /**
64
+ * The damping ratio, which dictates how the spring slows down.
65
+ *
66
+ * Set to `0` to never slow down. Set to `1` to slow down without bouncing.
67
+ * Between `0` and `1` is for you to explore.
68
+ *
69
+ * Defaults to `1` when `frequency` is defined.
70
+ */
71
+ damping ?: number
61
72
/**
62
73
* The damping ratio coefficient, or just the damping ratio when `speed` is defined.
63
74
*
You can’t perform that action at this time.
0 commit comments