xxxxxxxxxx
69
let label = "U";
let numCurves = 2;
let mic;
let amplitude;
function setup() {
createCanvas(600, 850);
mic = new p5.AudioIn();
mic.amp(10);
mic.start();
amplitude = new p5.Amplitude();
}
function draw() {
background(0, 20);
scale(2);
translate(-150, -70);
noFill();
// fill(255);
// noStroke();
stroke(255, 10);
let volume = mic.getLevel();
for (let i = 0; i < numCurves; i++) {
// Calculate control points for each curve
let x1 = 200 + i * 100;
let y1 = 160;
let x2 = 380 + i * 100;
let y2 = 80;
let x3 = 40 + i * 100;
let y3 = 470;
let x4 = 300 + i * 100;
let y4 = 340;
// Use the parameter t to create motion
let frequency = 1; // Adjust this value for motion intensity
beginShape();
for (let t = 0; t <= 1; t += 0.01) {
let xt = bezierPoint(x1, x2, x3, x4, t);
let yt = bezierPoint(y1, y2, y3, y4, t);
let xOffset = cos(frequency * (frameCount * 0.02 + i)) * 10;
let yOffset = cos(frequency * (frameCount * 0.02 + i)) * 10;
// Adjust the size of the rectangles based on the audio amplitude
// Adjust the size of the rectangles based on the audio amplitude
let rectSize = map(volume, 0, 1, 10, 200); // Adjust the size range as needed
ellipse(xt + xOffset, yt + yOffset, rectSize, rectSize);
}
endShape();
}
}
function keyPressed() {
if (key === "s") {
if (this._renderer.elt.svg !== undefined) {
saveSVG(label + ".svg");
} else {
saveCanvas(label + ".png");
}
}
}