Hello Processing community,
I'm sure it will appear pretty easy to most of you, but ive been bumping my head on this, as im quite new to any kind of coding (manipulating arrays is still tricky to me..)
The bubbles change diameter, speed, fill color and connectivity along with audio input (microphone). I vary the speed with a USB MiDi controller, and i would also like to control the number of bubbles with this device. But I get an error as soon as i touch my slider. I understand it, you would have to assign it a random position aswell. I still wonder how to write it though. Can someone tell?
thanks in advance
Code:import krister.Ess.*;
import themidibus.*;
MidiBus myBus;
AudioInput sound_input;
FFT analyse_fft;
int buffer = 512;
float normalisation;
int Bubbles = 8; // number of Bubbles
int frameX = 640; int frameY = 480; // frame definition
float inc = 0.0025; // move increasement every loop
float[] ptsX = new float[Bubbles]; // declare + create array X
float[] ptsY = new float[Bubbles]; // declare + create array Y
float[] posX = new float[Bubbles]; // declare + create array X
float[] posY = new float[Bubbles]; // declare + create array Y
void setup() {
size(frameX, frameY);
myBus = new MidiBus(this, "nanoKONTROL 1 SLIDER/KNOB", "nanoKONTROL 1 CTRL");
///////////// Starts Audio Analyser
Ess.start(this);
sound_input=new AudioInput(buffer);
analyse_fft=new FFT(buffer * 100);
analyse_fft.equalizer(true);
float min_limit=.005;
float max_limit=.05;
analyse_fft.limits(min_limit,max_limit);
analyse_fft.damp(.1f);
analyse_fft.averages(32);
normalisation = max_limit - min_limit;
sound_input.start();
/////////////
smooth();
for (int i = 0; i < Bubbles; i++) {
ptsX[i] = random(0, frameX); // write starting pts to arrayX
ptsY[i] = random(0, frameY); // write starting pts to arrayY
posX[i] = ptsX[i];
posY[i] = ptsY[i];
}
}
void draw() {
background(20);
float Level = analyse_fft.getLevel(sound_input) * 2000;
fill(38,Level,131,200+Level/200);
stroke(64,193,255,100);
// Update the Bubbles positions
for (int i = 0; i < Bubbles; i++) {
posX[i] = noise(ptsX[i]) * frameX; // Update the screen position
posY[i] = noise(ptsY[i]) * frameY;
ptsX[i] = ptsX[i] + (inc*Level/100); // Update position in Perlin noise space
ptsY[i] = ptsY[i] + (inc*Level/100);
}
// Draw the connecting lines
strokeWeight(2);
for (int i = 0; i < Bubbles - 1; i++) {
for (int j = i; j < Bubbles; j++) {
if (dist(posX[j], posY[j], posX[i], posY[i]) < 10*Level/10) {
line(posX[j], posY[j], posX[i], posY[i]);
}
}
}
// Draw the Bubbles
strokeWeight(0.5+Level/20);
for (int i = 0; i < Bubbles; i++) {
ellipse(posX[i], posY[i],7+Level/5,7+Level/5);
}
}
void controllerChange(int channel, int number, int value) { //Use the MIDI controller sliders
switch(number) {
case 1:
inc = value;
inc = inc/1000;
break;
case 2:
Bubbles = value; // 0 < value < 127
break;
}
}
//sound input stop
public void audioInputData(AudioInput theInput) {
analyse_fft.getSpectrum(sound_input);
}
//close audio input
public void stop() {
Ess.stop();
super.stop();
}