Uses the same algorithm as movingAverageLight, but adds values automatically if
nothing has been manually added.
// By default, 0 is added if interval elapses constmat = movingAverageTimed({ interval:1000 }); mat(10); // Add value of 10, returns latest average
mat(); // Get current average
This is useful if you are averaging something based on events. For example calculating the
average speed of the pointer. If there is no speed, there is no pointer move event. Using
this function, value is added at a rate of updateRateMs. This timer is reset
every time a value is added, a bit like the debounce function.
Use an AbortSignal to cancel the timer associated with the movingAverageTimed function.
Uses the same algorithm as movingAverageLight, but adds values automatically if nothing has been manually added.
This is useful if you are averaging something based on events. For example calculating the average speed of the pointer. If there is no speed, there is no pointer move event. Using this function,
value
is added at a rate ofupdateRateMs
. This timer is reset every time a value is added, a bit like thedebounce
function.Use an AbortSignal to cancel the timer associated with the
movingAverageTimed
function.