export const DEFAULT_TIME_SCALE = 1 / 100 ; export interface SpringConfig { position : number ; velocity : number ; equilibrium : number ; angularFrequency : number ; dampingRatio : number ; timeScale : number ; timeStart : number ; } const DEFAULT_CONFIG = { position : 0 , velocity : 0 , equilibrium : 100 , angularFrequency : 1 , dampingRatio : 1 , timeScale : 1 / 100 , timeStart : 0 , } ; export const SpringConfig = { defaults , basic , gentle , wobbly , stiff , slow , decay , static : staticConfig , findEquilibrium , angularFrequencyFromMass , angularFrequencyFromSpringConstant , } ; function defaults ( config = { } ) { return { ... DEFAULT_CONFIG , ... config , } ; } function basic ( config = { } ) { return { angularFrequency : 1 , dampingRatio : 1 , ... config , } ; } function gentle ( config = { } ) { return { angularFrequency : 0.6 , dampingRatio : 0.6 , ... config , } ; } function wobbly ( config = { } ) { return { angularFrequency : 0.8 , dampingRatio : 0.4 , ... config , } ; } function stiff ( config = { } ) { return { angularFrequency : 1.1 , dampingRatio : 0.7 , ... config , } ; } function slow ( config = { } ) { return { angularFrequency : 0.5 , dampingRatio : 1 , ... config , } ; } function decay ( config = { } ) { const resolved = { ... DEFAULT_CONFIG , ... config , } ; const equilibrium = resolved . position + findEquilibrium ( resolved . velocity , resolved . angularFrequency ) ; return { ... config , dampingRatio : 1 , equilibrium , } ; } function staticConfig ( equilibrium , config = { } ) { return { ... config , velocity : 0 , position : equilibrium , equilibrium , } ; } /**
 * Find the equilibrium position for a Critically damped spring
 */ function findEquilibrium ( velocity , angularFrequency = 1 ) { return velocity / angularFrequency ; } param springContant param mass function angularFrequencyFromMass ( mass , springContant = 1 ) { return Math . sqrt ( springContant / mass ) ; } param springContant param mass function angularFrequencyFromSpringConstant ( springContant , mass = 1 ) { return Math . sqrt ( springContant / mass ) ; }