Lens Scripting API
    Preparing search index...

    A 1D spring simulation class for smooth, physically-based animations of numbers.

    Index

    Constructors

    • Creates a 1D spring animator.

      Parameters

      • k: number

        Spring constant (stiffness).

      • damp: number

        Damping coefficient.

      • mass: number

        Mass of the simulated value.

      Returns SpringAnimate1D

    Properties

    damp: number

    Damping constant (resistance).

    k: number

    Spring constant (stiffness).

    mass: number

    Mass of the simulated value.

    onSettled: () => void = null

    A callback that fires once when the spring settles at its target.

    velocity: number

    Current velocity of the simulated value.

    Methods

    • Convenience factory for a bouncy spring with noticeable overshoot.

      Parameters

      • duration: number = DEFAULT_DURATION_BOUNCY

        Total perceptual duration in seconds (default: 0.5).

      Returns SpringAnimate1D

      A SpringAnimate1D configured for bouncy motion.

    • Evaluates the new value based on the spring dynamics.

      Parameters

      • currentValue: number

        The current value.

      • targetValue: number

        The target value.

      Returns number

      The updated value.

    • Checks if the spring has effectively come to rest at the target value.

      Parameters

      • currentValue: number

        The current simulated value.

      • targetValue: number

        The value the spring is moving towards.

      • positionThreshold: number = 0.1

        How close the value needs to be to the target.

      • velocityThreshold: number = 0.1

        How low the velocity needs to be.

      Returns boolean

      True if the spring is settled, false otherwise.

    • Resets the spring's velocity and time accumulator to zero.

      Returns void

    • Retunes this spring to match a desired duration and bounce. Preserves current velocity/accumulator by default to maintain continuity.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • bounce: number = BOUNCE_SMOOTH

        Bounce factor in [0,1], default 0 (smooth/critically-damped).

      • preserveVelocity: boolean = true

        If false, velocity/accumulator are reset.

      Returns void

    • Retunes to the bouncy profile.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • preserveVelocity: boolean = true

        If false, resets velocity/accumulator.

      Returns void

    • Retunes to the smooth profile.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • preserveVelocity: boolean = true

        If false, resets velocity/accumulator.

      Returns void

    • Retunes to the snappy profile.

      Parameters

      • duration: number

        Perceptual duration in seconds.

      • preserveVelocity: boolean = true

        If false, resets velocity/accumulator.

      Returns void

    • Convenience factory for a smooth, critically-damped spring with no bounce.

      Parameters

      • duration: number = DEFAULT_DURATION

        Total perceptual duration in seconds (default: 0.3).

      Returns SpringAnimate1D

      A SpringAnimate1D configured for smooth motion.

    • Convenience factory for a snappy spring with slight bounce.

      Parameters

      • duration: number = DEFAULT_DURATION

        Total perceptual duration in seconds (default: 0.3).

      Returns SpringAnimate1D

      A SpringAnimate1D configured for snappy motion.

    • Creates a new spring animation with the given duration and bounce.

      Parameters

      • duration: number

        The perceptual duration of the animation in seconds.

      • bounce: number

        How much bounce the spring should have. 0 is no bounce.

      Returns SpringAnimate1D

      A new 1D spring animation object.