const settings = {
ageMod: perSecond(0.1);
};
let state = {
age: 1
};
// Update
setInterval(() => {
let { age } = state;
// Add 0.1 per second, regardless of
// loop speed
age += settings.ageMod();
state = {
...state,
age: clamp(age)
}
});
Use the clamp option so the returned value never exceeds amount.
Alternatively, min/max options allow you to set arbitrary limits.
Returns a proportion of
amountdepending on elapsed time. Cumulatively,amountis yielded every second.The faster
x()is called, the smaller the chunks ofamountare returned. Values accumulate. For example,x()isn't called for two seconds, 2*amount is returned.