the nature of code cosmos edition from Amelia winger-bearskin on Vimeo.
this is the text from Carl Sagan’s “Cosmos”
the song I wrote was during the workshop the Nature of Code: Cosmos Edition by Dan Shiffman we had this past Saturday. He took us to a planetarium to try out some ideas for visualization of data in space or from space.
So this is more of a metaphor than useful space details but it will look cool on Friday projected in the planetarium. My voice changes the colors and size of the text…..
import ddf.minim.*;
import ddf.minim.analysis.*;
AudioPlayer[] player = new AudioPlayer[2];
Minim minim;
FFT fft;
float val;
int val2;
int bufferSize = 6;
int fftSize = floor(bufferSize*.9)+1;
int count=0;
IntDict concordance;
// The raw array of words in
String[] tokens;
int counter = 0;
void setup() {
size(800,800);
minim = new Minim(this);
player[0] = minim.loadFile(“cosmos.mp3”);
player[1] = minim.loadFile(“magpie.mp3”);
player[count].play();
fft=new FFT(player[count].bufferSize(), player[count].sampleRate());
//cosmos text
concordance = new IntDict();
// Load file and chop it up
String[] lines = loadStrings(“COSMOS.txt”);
String allText = join(lines, ” “).toLowerCase();
tokens = splitTokens(allText, “,.?!:;[]-\””);
// Create the font
textFont(createFont(“Georgia”, 24));
}
void draw()
{ background(0);
if(!player[count].isPlaying())
{
count++;
if(count>3)count=0;
player[count].play();
}
fft.forward(player[count].mix);
for (int i = 0; i < fftSize; i++)
{ float band = fft.getBand(i);
float control,afactor=10;
control=band*afactor;
if(control>1023)control=1023; ///get the value of this instead of delaying the sketch…instead of delay it will read every 5 seconds so its
val=map(control, 0, 1023, 0, 255);
val2=int(val);
print(“chanel “);
print(i);
print(” actual value “);
print(val2);
println();
stroke(val2,20*count,val2-100*i,i*val2);
//cosmos text
if (counter < tokens.length) {
String s = tokens[counter];
counter++;
concordance.increment(s);
}
// x and y will be used to locate each word
float x = 0;
float y = 48;
concordance.sortValues();
//delay(100);
String[] keys = concordance.keyArray();
// Look at each word
for (String word : keys) {
int count = concordance.get(word);
// Only display words that appear less than 3 times
if (count < 15) {
// The size is the count
//int fsize = constrain(count, 36,15);
int txtsize= constrain(height,width/7,val2);
fill(val2,i*25,i*val2*count );
textSize(txtsize);
text(word+val2, x, y);
// Move along the x-axis
x += textWidth(word + ” “);
}
// If x gets to the end, move y
if (x > width) {
x = 0;
y+= 60;
// If y gets to the end, we’re done
if (y > height) {
// break;
}
}
}
}
}