const sec = 5, Fs = 10000, size = sec * Fs, dotsPerFrame = 1000;
let freq1, freq2, ringRatio, modXTime;
let drawIndex = 0, startTime = 0, soundWave = [];
let waveHeight, halfHeight, randDelay;
createCanvas(windowWidth, windowHeight);
let AudioContext = window.AudioContext || window.webkitAudioContext;
audioCtx = new AudioContext();
freq1 = random(100, 400) * TWO_PI / Fs;
freq2 = random(100, 400) * TWO_PI / Fs;
ringRatio = random(0.25, 0.75);
modXTime = random(0.5, 1) ** 3 * 3;
for (let i = 0, l = sec * Fs; i < l; i++) {
let mAmp = mt / pow(mt, mt);
let s = lerp(s1, s1 * s2, ringRatio * mAmp);
let array = audioCtx.createBuffer(1, size, Fs);
let buff = array.getChannelData(0);
let source = audioCtx.createBufferSource();
source.connect(audioCtx.destination);
let length = min(size, drawIndex + dotsPerFrame);
for (; drawIndex < length; drawIndex++) {
let x = drawIndex / size * width + pow(random(), 7) * randDelay;
rect(x, halfHeight - soundWave[drawIndex] * waveHeight, 1, 1)
if (drawIndex >= size - 1) {
if (keyIsDown(27)) noLoop();
let elapsedSec = (Date.now() - startTime) / 1000;
rect(0, height - 3, elapsedSec / sec * width, 3)
function mousePressed() {
if (Date.now() - startTime < sec * 1000) return;