Skip to content

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 spring
const s = 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.

Generator

An alternative is to use the spring , which returns a generator instead. 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 spring
const s = Modulation.spring({
damping: 1,
stiffness: 10
});
// In a loop, read value and do something
Flow.continuously(() => {
const { value, done } = s.next();
if (done) return false; // Exit loop
// Do something with value...
}, 10).start();