I am very new to this but like to jump in at the deep end and learn that way. I’m making a fork of an existing processing prog. and wishing to use sound rather than mouse to interact with it. I’ve probably done lots of things wrong but currently stuck on a ‘for’ statement. Can somebody look at code and see how and can fix and move on. The original prog can be found on https://www.openprocessing.org/sketch/386707. Its rather fab… Here is my attempt to convert so far. Thank you in advance for any help offered
let input;
let mic;
let analyzer;
let spectrum = [];
let thold = 5;
let spifac = 1.05;
var outnum;
let drag = 0.01;
var big = 500;
let bodies = [];
let mX;
let mY;
function setup() {
createCanvas(900, 450);
strokeWeight(1);
fill(255, 255, 255);
stroke(255, 255, 255, 5);
background(0, 0, 0);
smooth();
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
X = random(screen.width);
Y = random(screen.height);
w = random(1 / thold, thold);
for (s = 0; s < spectrum.length; s++)
for (var i = 0; i < big; i++) {
bodies[i] = new ball(big);
}
}
function draw() {
let volume = mic.getLevel();
let spectrum = fft.analyze();
let threshold = 0.1;
if (volume > threshold) {
saveFrame("Focus " + outnum);
outnum++;
}
if (volume > threshold) {
background(0, 0, 0);
mX += 0.3 * (volume ^ 2 - mX);
mY += 0.3 * (volume ^ 2 - mY);
}
mX += 0.3 * (volume ^ 2 - mX);
mY += 0.3 * (volume ^ 2 - mY);
for (var i = 0; i < big; i++) {
bodies[i].render();
}
}
class ball {
constructor(X, Y, Xv, Yv, pX, pY) {
this.X = X;
this.Y = Y;
this.Xv = Xv;
this.Yv = Yv;
this.pX = pX;
this.pY = pY;
}
}
let w;
new ball(); {
}
function render() {
if (volume > threshold) {
Xv /= spifac;
Yv /= spifac;
}
Xv += drag * (mX - X) * w;
Yv += drag * (mY - Y) * w;
X += Xv;
Y += Yv;
}