Skip to content

Instantly share code, notes, and snippets.

@manuelzs
Created March 27, 2011 23:50
Show Gist options
  • Select an option

  • Save manuelzs/889771 to your computer and use it in GitHub Desktop.

Select an option

Save manuelzs/889771 to your computer and use it in GitHub Desktop.
/*
* Copyright 2011, Manuel Zapata
*/
// Import the sonia lib
import pitaru.sonia_v2_9.*;
// Vector to store the glow of each point
int[] glow;
void setup() {
// Set up a nice long screen
size(700,130);
// Start the sonia engine
Sonia.start(this);
// Start the microphone
LiveInput.start();
// Initialize the glow vector and set it to zero
glow = new int[1024];
for (int i = 0; i < glow.length; i++) {
glow[i] = 0;
}
noStroke();
background(0,0,0);
}
void draw() {
// Update the spectrum vector with the current data from the mic.
LiveInput.getSpectrum();
// Glow an ellipse for every spectrum position
for ( int i = 0; i < LiveInput.spectrum.length; i++){
// If the position is bigger than the threshold (80) glow
if((int)LiveInput.spectrum[i] > 80) {
glow[i] = (int)LiveInput.spectrum[i];
}
// Lose glow in time for every dot
else {
if (glow[i] > 1)
glow[i] -= 2;
}
// Pich the color (brightness) from the glow vector
fill(glow[i]);
// Draw an ellipse for each position of the spectrum with the glow from the glow vector
// The dots fill the screen from the bottom and the dots line is wrapped upwards
ellipse((i*10+5)%width,height - (10 * (int)((i * 10 +5) / width)) -5, 5, 5);
}
}
// Clean up
public void stop() {
super.stop();
Sonia.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment