Usage
Simple
Section titled “Simple”The simple way to use waveforms with ixfx is with springValue. It returns a function which in turn provides numeric values.
import { Modulation } from 'https://unpkg.com/ixfx';
// Set up springconst s = Modulation.springValue({ stiffness: 100, damping: 10});
// Later, call s() when we want a values(); // Yields a numberOptions for springValue are documented. Generally, tweaking the stiffness and damping values is enough.
Generator
Section titled “Generator”An alternative is to use spring, which returns a generator. The benefit of the generator is you can check when the spring has finished moving using the done property.
import { Flow, Modulation } from "https://unpkg.com/ixfx";
// Set up the springconst s = Modulation.spring({ damping: 1, stiffness: 10});
// Run in a loop, every 10 millisecondsFlow.continuously(() => { // Read value and done state from generator const { value, done } = s.next(); if (done) return false; // Exit loop
// Do something with value...}, 10).start();