function drawNoise(
context,
{ octaves = 1, width, height, scale = 2 ** -5 } = {}
) {
const aspectRatio = height / width;
const image = context.createImageData(width * dpr, height * dpr);
const imageDataWidth = width * dpr * 4;
for (let i = 0; i < image.data.length; i += 4) {
const x = (i % imageDataWidth) / 4;
const y = Math.floor(i / imageDataWidth / 2);
const xScale = scale;
const yScale = scale / aspectRatio;
const noiseFn = octave(noise2DB, octaves + 1);
const noise = noiseFn(x * xScale, y * yScale);
const u = 0.5 + noise * 0.5;
const v = Math.trunc(math.lerp(0, 255, u));
image.data[i + 0] = v;
image.data[i + 1] = v;
image.data[i + 2] = v;
image.data[i + 3] = 255;
}
context.putImageData(image, 0, 0);
}