Skip to content

Usage

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 spring
const s = Modulation.springValue({
stiffness: 100,
damping: 10
});
// Later, call s() when we want a value
s(); // Yields a number

Options for springValue are documented. Generally, tweaking the stiffness and damping values is enough.

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 spring
const s = Modulation.spring({
damping: 1,
stiffness: 10
});
// Run in a loop, every 10 milliseconds
Flow.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();