Simulator

public class Simulator<Value, Function> where Value: VectorConvertible, Function: SimulationFunction, Value.VectorType == Function.VectorType

Animates changes to a value using a simulation function.

In most scenarios, physics-based animations are simply run to completion. For those situations, PropertyAnimator makes it easy to run and use the results of an animation.

In contrast, Simulator is useful for scenarios where you need direct access to a running simulation. This might occur in a UI where the user’s scroll position drives changes to a spring’s tension, for example. It would be impractical to create and start a new animation every time the simulation needs to change. A Simulator instance provides mutable access to the function property (containing the underlying function that is driving the simulation), along with the current state of the simulation (value and velocity).

  • The function driving the simulation.

    Declaration

    Swift

    public var function: Function
  • Creates a new Simulator instance

    Declaration

    Swift

    public init(function: Function, value: Value, velocity: Value = Value.zero)

    Parameters

    function

    The function that will drive the simulation.

    value

    The initial value of the simulation.

    velocity

    The initial velocity of the simulation.

  • The current value of the spring.

    Declaration

    Swift

    public var value: Value
  • The current velocity of the simulation.

    Declaration

    Swift

    public var velocity: Value
  • Initializes a new spring converged at the given value, using default configuration options for the spring function.

    Declaration

    Swift

    public convenience init(value: Value)
  • The spring’s target.

    Declaration

    Swift

    public var target: Value
  • Removes any current velocity and snaps the spring directly to the given value.

    Declaration

    Swift

    public func reset(to value: Value)

    Parameters

    value

    The new value that the spring will be reset to.

  • How strongly the spring will pull the value toward the target,

    Declaration

    Swift

    public var tension: Scalar
  • The resistance that the spring encounters while moving the value.

    Declaration

    Swift

    public var damping: Scalar
  • The minimum distance from the target value (for each component) that the current value can be in order to ender a converged (settled) state.

    Declaration

    Swift

    public var threshold: Scalar