Usage
Simple
The simple way to use waveforms with ixfx is with springValue . It returns a function which in turn provides numeric values.
import { springValue } from 'https://unpkg.com/ixfx/dist/modulation.js';
// Set up springconst s = springValue({ stiffness: 100, damping: 10});
// Later, call s() when we want a values(); // Yields a number
Options for springValue
are documented . Generally, tweaking the stiffness and damping values is enough.
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/dist/bundle.js"
// 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();