We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Real Time Array Extension
Page Index Toggle Pages: 1
Real Time Array Extension (Read 965 times)
Real Time Array Extension
Mar 8th, 2010, 11:08am
 
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();
}

Re: Real Time Array Extension
Reply #1 - Mar 8th, 2010, 11:24am
 
http://processing.org/reference/ArrayList.html
Re: Real Time Array Extension
Reply #2 - Mar 8th, 2010, 11:55am
 
Problem:

Code:
int Bubbles = 8;	// number of Bubbles
float[] ptsX = new float[Bubbles]; // array size 8!

// ...

// BAD! Arrays are only size 8...
Bubbles = value; // 0 < value < 127


Fix:

Code:
int MAX_BUBBLES = 128; // or whatever your max is
int Bubbles = 8; // CURRENT number of Bubbles
float[] ptsX = new float[MAX_BUBBLES];

// ...

// Make it so that: 0 <= value <= MAX_BUBBLES
Bubbles = constrain(value, 0, MAX_BUBBLES);


-spxl
Re: Real Time Array Extension
Reply #3 - Mar 8th, 2010, 2:44pm
 
thank u guys, especially subpixel for taking the time to explain,
I got it now!
Re: Real Time Array Extension
Reply #4 - Apr 11th, 2010, 3:33am
 
Off-Topic replies have been moved to this Topic.
Page Index Toggle Pages: 1