::: Cells are now going faster and increase their connection radius with the sound intensity. They are mostly sensitive to low frequencies. A good minimal track with bass and breaks will clearly reveal their flocking rules. ::: enjoy



import krister.Ess.*;
AudioInput sound_input;
FFT analyse_fft;
int buffer = 1024;
//int buffer = 512;
float normalisation;

//import processing.video.*;
//MovieMaker mm; // Declare MovieMaker object


int fisheZ = 10; // amount of fisheZ
int frameX = 500; // frame definition
int frameY = 500; // frame size y-direction
float inc = 0.0035; // move increasement every loop // speed

float pX, pY, nX, nY;

float[] ptsX = new float[fisheZ]; // declare + create array X
float[] ptsY = new float[fisheZ]; // declare + create array Y

float[] posX = new float[fisheZ]; // declare + create array X
float[] posY = new float[fisheZ]; // declare + create array Y



void setup() {
size(frameX, frameY);
//frameRate(30);
//mm = new MovieMaker(this,frameX, frameY, "fish_Network",30, MovieMaker.H263, MovieMaker.HIGH);

Ess.start(this);//starts ESS
sound_input=new AudioInput(buffer);//get access to audio input
// start audio analyzer
analyse_fft=new FFT(buffer * 100);
analyse_fft.equalizer(true);
float min_limit=.005;//normalizing values
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();//starts your engines

smooth();

for (int i = 0; i <>
ptsX[i] = random(0, frameX); // write start pts to arrayX
ptsY[i] = random(0, frameY); // write start pts to arrayY
posX[i] = ptsX[i];
posY[i] = ptsY[i];
}
}

void draw() {

float Level = analyse_fft.getLevel(sound_input) * 3000; // sound value

//mm.addFrame(); // Add window's pixels to movie

background(20);
color cellfill = color(38,Level,131,200+Level/200);
color cellstroke = color(64,193,255,100);
fill(cellfill);
stroke(64,193,255,100);

// Update the fisheZ positions
for (int i = 0; i <>
posX[i] = noise(ptsX[i]) * frameX; // Update the screen position
posY[i] = noise(ptsY[i]) * frameY;
ptsX[i] = ptsX[i] + (inc*Level/80); // Update position in Perlin noise space
ptsY[i] = ptsY[i] + (inc*Level/80);
}

// Draw the connecting lines
strokeWeight(3);
for (int i = 0; i <>
for (int j = i; j <>
if (dist(posX[j], posY[j], posX[i], posY[i]) <>
line(posX[j], posY[j], posX[i], posY[i]);
}
}
}
// draw the fisheZ last so they are not masked by lines
strokeWeight(0.5+Level/20);
for (int i = 0; i <>
ellipse(posX[i], posY[i], 5+Level/10,3+Level/10); // insert ellipse/pts
}
}

//void keyPressed() {
// if (key == ' ') {
// mm.finish(); // Finish the movie if space bar is pressed!
// }
//}

///////////////////////////////////////////////////////////////////////////////////
//sound input stop
public void audioInputData(AudioInput theInput) {
analyse_fft.getSpectrum(sound_input);
}

//close audio input
public void stop() {
Ess.stop();
super.stop();
}






::: Cells now bounce on the frame. The speed increases and inside fill changes its color depending on sound input... I've created a class to build the cells. Suggestions are very welcome / Dont forget to download the Ess (see below) library if you want to use this code. Enjoy ::: François




import krister.Ess.*;
AudioInput entree_son;
FFT analyse_fft;

int buffer = 512;
float normalisation;

//import processing.video.*;
//MovieMaker mm; // Declare MovieMaker object

//..................................................................................................................
Cell myCell1;
Cell myCell2;
Cell myCell3;
Cell myCell4;
Cell myCell5;
Cell myCell6;
Cell myCell7;
Cell myCell8;
Cell myCell9;
Cell myCell10;

float niveau;
float size = 100; // diameter
float xpos, ypos; // starting position of the shape / dynamic coordinates definition
int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom

//..................................................................................................................
void setup() {

size(860,600);
frameRate(60);
smooth();//anti aliasing

//mm = new MovieMaker(this, 860, 600, "6ellipses.mov",30, MovieMaker.H263, MovieMaker.HIGH);

myCell1 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.8,0.2,xdirection,ydirection);
myCell2 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.4,0.1,xdirection,ydirection);
myCell3 = new Cell (color (niveau,niveau,niveau),xpos,ypos,1,0.3,xdirection,ydirection);
myCell4 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.7,0.9,xdirection,ydirection);
myCell5 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.1,0.1,xdirection,ydirection);
myCell6 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.2,0.05,xdirection,ydirection);
myCell7 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.4,0.9,xdirection,ydirection);
myCell8 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.11,0.3,xdirection,ydirection);
myCell9 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.2,0.5,xdirection,ydirection);
myCell10 = new Cell (color (niveau,niveau,niveau),xpos,ypos,0.6,0.5,xdirection,ydirection);


Ess.start(this);
entree_son=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;
entree_son.start();

}

//..................................................................................................................
void draw() {

background(10);
myCell1.move();
myCell2.move();
myCell3.move();
myCell4.move();
myCell5.move();
myCell6.move();
myCell7.move();
myCell8.move();
myCell9.move();
myCell10.move();

//mm.addFrame(); // Add window's pixels to movie


}

//..................................................................................................................
class Cell {
color c;
float xpos;
float ypos;
float xspeed;
float yspeed;
float xdirection;
float ydirection;

Cell(color tempC, float tempXpos, float tempYpos, float tempXspeed, float tempYspeed, float tempXdirect, float tempYdirect) {
c = tempC;

xpos = width/2;
ypos = height/2;
xspeed = tempXspeed;
yspeed = tempYspeed;
xdirection = tempXdirect;
ydirection = tempYdirect;
}

//..................................................................................................................
void move() {

float niveau = analyse_fft.getLevel(entree_son) * 2000;

c = color(48,niveau,131,200);

xspeed = xspeed + ((niveau/500)*(niveau/500));
if(xspeed >= 4) { // in case they are too fast, slow them down
xspeed = yspeed/5;
}

yspeed = yspeed + ((niveau/500)*(niveau/500));
if(yspeed >= 4) {
yspeed = yspeed/5;
}

stroke(64,193,255);
strokeWeight(niveau/10); // parametric stroke depending on sound input
//noStroke();
fill(c);
//noFill();
ellipseMode(CENTER);
ellipse(xpos,ypos,size+niveau/10,size+niveau/10);

xpos = xpos + (xspeed * xdirection);
if (xpos > width|| xpos < ypos =" ypos"> height || ypos < key ="=">




:::: You first have to download Ess sound librairy [here] in order to play. The ellipse reacts to the sound input from the computer's microphone (arduino is not plugged yet). It accelerates and changes its diameter/stroke weight depending on the sound intensity ::::


import krister.Ess.*;
AudioInput entree_son;
FFT analyse_fft;

int buffer = 512;
float normalisation;


// cell behavior variables
color insideCell = color (100,100,200);
color outsideCell = color (100,150,255);

float x = 0;
float y = 100;

float widthA = 100;
float heightA = 100;

void setup() {

size(1000,600);
frameRate(1000);

// starts ess
Ess.start(this);
// get access to audio input
entree_son=new AudioInput(buffer);
// start audio analyzer
analyse_fft=new FFT(buffer * 100);
analyse_fft.equalizer(true);

// normalizing values
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;

// starts your engines
entree_son.start();

}


void draw() {

// fond gris
background(100);
move();
}

void move () {

float niveau = analyse_fft.getLevel(entree_son) * 2000;
//println (niveau);//prints sound input value

x = x + (niveau/50)*(niveau/50); // parametric speed depending on sound input
if (x > width) {
x = 0;
}

y = y + (niveau/50)*(niveau/50);
if (y > width) {
y = 0;
}

smooth();//anti aliasing
stroke(outsideCell);
strokeWeight(niveau/10); // parametric stroke depending on sound input
//noStroke();
fill(insideCell);
//noFill();


//if (mouseButton== LEFT){
ellipse(x, y, widthA+niveau/5,heightA+niveau/5); // parametric diameter depending on sound input
//ellipse(x, y, widthA,heightA);
// }

}


public void audioInputData(AudioInput theInput) {
analyse_fft.getSpectrum(entree_son);
}

//close audio input
public void stop() {
Ess.stop();
super.stop();
}