A sound bubble I like very much
import processing.sound.*; int amount = 50; //Amount of bubbles float[] x = new float[amount]; float[] y = new float[amount]; float[] size = new float[amount]; float[] speed = new float[amount]; SinOsc[] sine = new SinOsc[amount]; Env[] env = new Env[amount]; float[] freq = new float[amount]; void setup() { size(360, 640); //Assigning random values for x,y, size and speed of bubbles for(int i=0; i<amount; i++) { x[i] = random(width); y[i] = random(height, height * 2); size[i] = random(10, 50); speed[i] = map(size[i], 10, 50, 1, 5);//the size is depending on how big is the bubble sine[i] = new SinOsc(this);//for each of them there is a new sine of this env[i] = new Env(this); freq[i]= map(size[i],10,50,500,100);//10size bubble have the higher pitch,500 is the pitch match to the 10 of size bubble } } void draw() { background(255); fill(0,0,255); rect(0, 80, width, height); //draw bubbles for(int i=0; i<amount; i++) { noStroke(); fill(255, 120); circle(x[i], y[i], size[i]); // Bubbles float to the top y[i] -= speed[i]; // if bubbles reaches the surface, create a new random bubble if(y[i] < 80+(size[i]/2)) { x[i] = random(width); y[i] = random(height, height * 2); size[i] = random(10, 50); speed[i] = map(size[i], 10, 50, 1, 5); sine[i]. freq(freq[i]); env[i]. play(sine[i],0.0005,0.05,0.2,0.001); freq[i] = map(size[i],10,50,500,100); sine[i].play(); } } }
会动的声音圈 import processing.sound.*; // Declare the sound source and FFT analyzer variables FFT fft; AudioIn mic; // Define how many FFT bands to use (this needs to be a power of two) int bands = 1024; // Define the bands wanted for our visualization. // Above a certain threshold, high frequencies are rarely attained and stay flat. int bandsWanted = 128; // Create an array to store the bands wanted float[] spectrum = new float[bandsWanted]; float gap; float position; float spinSpeed; float duration; void setup() { background(255); size(600, 600); // Create the AudioIn object and select the mic as the input stream mic = new AudioIn(this, 0); // Start the input stream without routing it to the audio output. mic.start(); // Create the FFT analyzer and connect it to the sound input fft = new FFT(this, bands); fft.input(mic); //adjust the gap gap = (width/2) / (float)bandsWanted; //how long duration = 2; // how fast spinSpeed = radians(180)/(duration*frameRate); } void draw() { //background(255); // Perform the analysis fft.analyze(spectrum); //Here we are reversing the spectrum array in order to get the higher frequencies on the right edge of canvas. spectrum = reverse(spectrum); pushMatrix(); //Translating the position to start drawing in the middle translate(width/2, height/2); position += spinSpeed; rotate(position); if(frameCount <= duration*frameRate){ //Drawing a line for every frequency of the spectrum for (int i=0; i<bandsWanted; i++) { stroke(#E7C1FF); line( i*gap, 0, i*gap, -spectrum[i]*1000 ); } } else{ noStroke(); } popMatrix(); }