A simple spring simulation for smooth, physically-inspired animations.
This module provides a spring model that moves a value toward a target over time, based on configurable tension and friction. It can be used to animate values like positions, sizes, or any other continuous quantity.
Create a new Spring given an initial value and a target.
The initial velocity will be zero.
create { value = 0, target = 100 }Step the spring simulation forward by a given number of milliseconds.
Applies the configured spring dynamics to update the value and velocity.
If the spring is close enough to equilibrium (as defined by the threshold in the config), it snaps to rest.
update myConfig 16 mySpringCheck if a Spring is at equilibrium.
This returns True if the value equals the target and the velocity is zero.
equilibrium mySpringConfiguration for a spring simulation.
Includes:
tension: how strongly the spring is pulled toward the targetfriction: how much resistance slows the spring downequilibriumThreshold: how close is “close enough” to be considered settledCreate a basic Config using the given tension and friction values.
The equilibriumThreshold is set to a default of 0.05, which defines how close the
spring’s value and velocity must be to the target and zero, respectively, before
it is considered at rest.
config { tension = 100, friction = 15 }Override the equilibriumThreshold of a given Config.
This can be useful if you want to change how strictly the spring checks for rest.
config { tension = 100, friction = 15 }
|> setEquilibriumThreshold 0.01
A
Springrepresents a value that moves toward a target using spring dynamics.It holds the current value, the target value, and the velocity of the spring.