p5(sketch => {
sketch.setup = function() {
sketch.createCanvas(width,height);
};
sketch.draw = function() {
sketch.background("#001b42");
sketch.fill("white");
sketch.noStroke();
const dim = sketch.min(width, height);
if (!sketch.mouseIsPressed) polygon(width / 2, height / 2, dim * 0.1, 3);
const u = sketch.max(0, sketch.min(1, sketch.mouseX / width));
const frequency = sketch.lerp(75, 2500, u);
synth.setNote(frequency);
if (sketch.mouseIsPressed) {
const time = sketch.millis() / 1000;
const verts = 1000;
sketch.noFill();
sketch.stroke('yellow');
sketch.strokeWeight(dim * 0.005);
sketch.beginShape();
for (let i = 0; i < verts; i++) {
const t = verts <= 1 ? 0.5 : i / (verts - 1);
const x = t * width;
let y = height / 2;
const frequencyMod = sketch.lerp(1, 1000, sketch.pow(u, 5));
const amplitude = sketch.sin(time + t * frequencyMod);
y += (amplitude * height) / 2;
sketch.vertex(x, y);
}
sketch.endShape();
}
}
sketch.mousePressed = function () {
synth.triggerAttack();
}
sketch.mouseReleased = function () {
synth.triggerRelease();
}
function polygon(x, y, radius, sides = 3, angle = 0) {
sketch.beginShape();
for (let i = 0; i < sides; i++) {
const a = angle + sketch.TWO_PI * (i / sides);
let sx = x + sketch.cos(a) * radius;
let sy = y + sketch.sin(a) * radius;
sketch.vertex(sx, sy);
}
sketch.endShape(sketch.CLOSE);
}
})