Function pingPongPercent

Continually loops up and down between 0 and 1 by a specified interval. Looping returns start value, and is inclusive of 0 and 1.

import {percentPingPong} from 'https://unpkg.com/ixfx/dist/modulation.js';
for (const v of percentPingPong(0.1)) {
// v will go up and down. Make sure you have a break somewhere because it is infinite
}
const pp = pingPongPercent(0.1, 0.5); // Setup generator one time
const v = pp.next().value; // Call .next().value whenever a new value is needed

Because limits are capped to -1 to 1, using large intervals can produce uneven distribution. Eg an interval of 0.8 yields 0, 0.8, 1

upper and lower define the percentage range. Eg to ping pong between 40-60%:

const pp = pingPongPercent(0.1, 0.4, 0.6);
  • Parameters

    • interval: number = 0.1

      Amount to increment by. Defaults to 10%

    • Optionallower: number
    • Optionalupper: number
    • Optionalstart: number

      Starting point within range. Defaults to 0 using a positive interval or 1 for negative intervals

    • Optionalrounding: number

      Rounding to apply. This avoids floating-point rounding errors.

    Returns Generator<number, never, unknown>