Adapted from tart-stepping/examples/multiplex.js