Clock

Clock is designed to work with elm-lang/animation-frame. Your model will get consistently-paced updates, despite fluctuations in frame diffs.

type Clock
= Clock
{ lag : Time
, period : Time
}

A clock.

withPeriod : Time -> Clock

Create a clock that updates with the given real-time period.

withDelta (100 * Time.millisecond) -- calls the tick function ten times per second

lag : Clock -> Time

Return the amount of lag between the animation frame and the last physics update.

update : (Time -> a -> a) -> Time -> Clock -> a -> ( Clock, a )

Called like so:

update up diff clock model

The diff is a real-time diff, such as what is given by AnimationFrame.diffs. This function will pass the diff to the clock. If the diff causes the clock's counter to increment, then up will be called with the period and the model.