## Floating Processing cloudes with minim

I made a simple example to test the sound input features of minim, an audio library for processing.

I took one of the cloudes i wrote for my ical-flowers and wrote a simple sketch that makes it float to the right whenever someone blows into the microphone. I didn't export it as an applet this time, but here is the code, in case you want to try it.

``````import ddf.minim.*;

Minim minim;
AudioInput in;

void setup() {
size( 500,300 );
smooth();
frameRate(25);
minim = new Minim(this);
in = minim.getLineIn( Minim.MONO, 512 );
}

int pos = 0;

void draw() {
background( 128, 128, 255 );
float m = 0;
for(int i = 0; i < in.bufferSize() - 1; i++) {
if ( abs(in.mix.get(i)) > m ) {
m = abs(in.mix.get(i));
}
}

pos += m * 50;
cloud( pos, 150, 80 );
if ( pos > width ) {
pos = 0;
}

}

void cloud( int x, int y, int w ) {
int u = w/6;
// this is a bit of a hack to prevent floating point rounding errors
int u15 = int(u * 1.5);
int u25 = int(u * 2.5);
fill(255, 200);

noStroke();
rect( x - 4 * u , y-u15, 8 * u + 1, 3*u );

stroke(0);
strokeWeight(2);

arc( x - 4 * u, y, 3 * u, 3 * u, PI/2 , PI * 1.5);
arc( x + 4 * u, y, 3 * u, 3 * u, PI*1.5, PI * 2.5);

arc( x - u15, y - u15, 5 * u, 5 * u, PI, 2*PI );
arc( x + u25, y - u15, 3 * u, 3 * u, PI, 2*PI );

line( x - 4 * u, y + u15, x + 4 * u, y + u15 );
}
``````