#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Change color of line based on song frequency.

edited December 2016

Hello,

I am trying to write a code that will use a song's frequency to change the color of a line that moves across the campus to create some sort of abstract picture. Currently, I am stumped on how to achieve this effect. If anyone has any advice on how to do this, it would be much appreciated.

This is my code currently (which probably has a great amount of errors in it; I'm still new to processing):

import ddf.minim.*; import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; float k; float r; float g; float b;

Minim minim; AudioPlayer player; FFT fft;

void setup() { size( 800, 600 );

``````minim = new Minim( this );

player.play();
fft = new FFT( player.bufferSize(), player.sampleRate() );
``````

}

void draw() {

``````float x = map( player.position(), 0, player.length(), 0, width );

float e = 0;
for ( int i = 0; i < fft.specSize(); i++ ) {
e += abs( fft.getBand( i ) ) / 1000;
``````

}

{ int k = color(r-e,g/e,b+e); float r = red(pixels[k]); float g = green(pixels[k]); float b = blue(pixels[k]);

}

``````stroke( color(r-e, g/e, b+e) );
strokeWeight (5);
line( x, 0, x, height );
``````

}

void stop() { player.close(); minim.stop(); super.stop(); }

Tagged:

• @jpnielsen -- agreed with LoG -- if you are trying to change a color, start with the Color Tutorial is the best link. Also, look specifically at the reference page for colorMode() for HSB color, and the `map()` reference for how to map something (like audio values) to something else (like HSB color values).