import ddf.minim.*; import ddf.minim.analysis.*; AudioPlayer song; FFT fft; float xmin = -2.5; float ymin = -2; float wh = 4; void setup() { size(300, 300); // always start Minim first! Minim.start(this); // specify 512 for the length of the sample buffers // the default buffer size is 1024 song = Minim.loadFile("freedom.mp3", 512); song.play(); // an FFT needs to know how // long the audio buffers it will be analyzing are // and also needs to know // the sample rate of the audio it is analyzing is fft = new FFT(song.bufferSize(), song.sampleRate()); } void draw() { background(0); // first perform a forward fft on one of song's buffers // I'm using the mix buffer // but you can use any one you like fft.forward(song.mix); loadPixels(); // Maximum number of iterations for each point on the complex plane int maxiterations = 200; // x goes from xmin to xmax float xmax = xmin + wh; // y goes from ymin to ymax float ymax = ymin + wh; // Calculate amount we increment x,y for each pixel float dx = (xmax - xmin) / (width); float dy = (ymax - ymin) / (height); // Start y float y = ymin; for(int j = 0; j < height; j++) { // Start x float x = xmin; for(int i = 0; i < width; i++) { // Now we test, as we iterate z = z^2 + cm does z tend towards infinity? float a = x; float b = y; int n = 0; while (n < maxiterations) { float aa = a * a; float bb = b * b; float twoab = 2.0 * a * b; a = aa - bb + x; b = twoab + y; // Infinty in our finite world is simple, let's just consider it 16 if(aa + bb > 16.0f) { break; // Bail } n++; } // We color each pixel based on how long it takes to get to infinity // If we never got there, let's pick the color black if (n == maxiterations) pixels[i+j*width] = 0; else pixels[i+j*width] = color(n*(song.right.get(i)*50) % 255, n*(song.left.get(i)*50) % 200, n*(song.right.get(i)*30)); // Gosh, we could make fancy colors here if we wanted x += dx; } y += dy; } updatePixels(); } void stop() { song.close(); super.stop(); }