float x = 0.0; float y = 0.0; float x2 = 0.0; float y2 = 0.0; float rot_deg_inc = radians(4); float cur_angle = 90; float i = 1; float change_ratio = 5; float Radius= 0.0; float max_lim = 20; float min_size = 10; float frame_rate = 30; float frame_speed = 10; boolean skip_radius_calc_once = false; //bezier variables float y_bez1 = 0.0; float x_bez1 = 0.0; float y_bez2 = 0.0; float x_bez2 = 0.0; float y_mid1 = 0.0; float x_mid1 = 0.0; float y_mid2 = 0.0; float x_mid2 = 0.0; //SET YOUR color variables //background, 0 is black 255 is white float back_grey = 255; //alpha is by percentage so this is faded 30% float alpha_fill = 80; //amount of time spent transitioning between colors float slow_colors_by = 1; //how big does the line need to be to change color? 2 is low 5 is high float color_change_ratio = 2; //initial fill colors when this thing starts float red_fill = 100; float blue_fill= 0; float green_fill= 100; //low and high limits to keep colors in a particular range float red_high_lim = 200; float red_low_lim = 50; float blue_high_lim = 200; float blue_low_lim = 0; float green_high_lim = 200; float green_low_lim = 50; //different ratios allow for the colors to scale idependently //if the ratios are equal you will stay in a tonal range... float red_ratio = .5; float blue_ratio = .5; float green_ratio = .5; float Sound_Color = 0; float Sound_Radius = 0; //change this to vary the S curve // 0 = a flat line // 0-30 slight cure // 30-45 moderate curve // 60 more dramatic // 75 sharp lip // 90 very dramatic (default) // 120 curve moves towards center // 150 doubles over itself // 180 point of rotation is at bez_ratio float bez_angle = radians(90); //change this to make the curve more or less dramatic //3 begins to form conelike shapes //2- is an avergae S curve like a pinwheel (default?) //1.5 produces a dramatic curve //1 is a very dramatic curve // under 1 increases the size of the curve float bez_ratio = 2; //shapes at 2,90 are very intersting... //vary this number between .25 and 3 to decrease the curve of the S //default is 1? float bez_amp = 1; //intialize the AI Export libarary //AIExport ai; void setup() { size(600,600); framerate(frame_speed); background(back_grey,back_grey,back_grey); smooth(); x = mouseX; y = mouseY; x2 = mouseX - max_lim; y2 = mouseY - max_lim; //initialize the AI Export // ai = new AIExport( this, 1 ); // ai.setFileName("string_" + day() + "-" + month() +"_"+ hour() +"_"+ minute() + ".ai"); // ai.turnTransparencyOff(); //live input sound initialization Sonia.start(this); // Start Sonia engine. LiveInput.start(64); // Start LiveInput and return 64 FFT frequency bands. } void loop() { // ai.run(); // ai.setLayer(1); // ai.setLineWeight(0.25); //if the mouse is pressed then we can begin the drawing if (mousePressed == true) { Start_Draw(); } else { //reset the radius of the drawing Radius = max_lim; skip_radius_calc_once = true; } // if( key=='e' ) ai.exportOneFrame(); // if( key=='s' ) ai.takeSnapShot(); // if( key=='d' ) ai.dumpSnapShots(); // if( key=='r' ) ai.toggleContinuousRecording(); getSpectrum(); getMeterLevel(); } //LIVE INPUT SOUND FUNCTIONS void getSpectrum(){ // populate the spectrum array with FFT values. LiveInput.getSpectrum(true,10); //for holding the top 5 values in the freqency float[] maxFreq = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] freqMarker = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; boolean marked = false; // draw a bar for each of the elements in the spectrum array. // Note - the current FFT math is done in Java and is very raw. expect optimized alternative soon. for ( int i = 0; i < LiveInput.spectrum.length; i++){ marked = false; for (int j = 0; j < 10; j++) { if (( LiveInput.spectrum[i] > maxFreq[j]) && (marked == false)) { freqMarker[j] = i; maxFreq[j] = LiveInput.spectrum[i]; marked = true; } } } Sound_Color = (freqMarker[0] + freqMarker[1] + freqMarker[2] + freqMarker[3] + freqMarker[4] + freqMarker[5] + freqMarker[6] + freqMarker[7] + freqMarker[8] + freqMarker[9]) / 10; //Sound_Color = an average of the top 10 freqency readings. //FreqMarker is a number between 0 and 63 //USE THIS NUMBER TO CHANGE THE COLORS } void getMeterLevel(){ // get Peak level for each channel (0 -> Left , 1 -> Right) // Value Range: float from 0.0 to 1.0 // Note: use inputMeter.getLevel() to combine both channels (L+R) into one value. float meterDataLeft = LiveInput.getLevel(Sonia.LEFT); // draw a volume-meter for each channel. Sound_Radius = meterDataLeft*200; // left fluxuates between 0 and 100; //USE This number to set a new size } //END LIVE INPUT SOUND FUNCTIONS void Start_Draw() { //this allows the center to change modestly in the direction of the user. x = mouseX; y = mouseY; //calculate the length of the radius if the mouse has not been lifted if (skip_radius_calc_once == false) { //Radius = sqrt(sq(x2-x) + sq(y2-y)); Radius = Sound_Radius*10 + min_size; println(Sound_Radius); } else { skip_radius_calc_once = false; } //calculate the current angle based on the x axis of the circle origin cur_angle = atan2(y2-(y), x2-(x)); //add a little to the angle to rotate the line cur_angle += rot_deg_inc; //acount for if we have gone around the circle (keep rotating in current direction) if(cur_angle > 2*PI) { cur_angle -= 2*PI; } //limit the size of the Radius if(Radius > max_lim) { Radius -= Sound_Radius/frame_rate; } //recalculate the x2 y2 points x2 = Radius * cos(cur_angle) + x; y2 = Radius * sin(cur_angle) + y; Get_Bez_Points(); Calculate_Colors(); //draw the line each one is based on... // stroke(100,0,0); // line(x,y,x2,y2); //finally lets draw the curve bezier(x,y,x_bez1,y_bez1,x_bez2,y_bez2,x2,y2); } void Calculate_Colors() { //increase the intensity of a color depending on SOUND //println("Radius = "+ Radius); //if the raidus is small make it lighter if (Sound_Color < max_lim*color_change_ratio) { if (red_fill >= red_low_lim){ red_fill -= (frame_rate/red_ratio)/slow_colors_by; } if (blue_fill >= blue_low_lim) { blue_fill -= (frame_rate/blue_ratio)/slow_colors_by; //println(blue_fill); } if (green_fill >= green_low_lim) { green_fill -= (frame_rate/green_ratio)/slow_colors_by; } } //if the radius is big increase intensity else { if (red_fill <= red_high_lim) { red_fill += (frame_rate/red_ratio)/slow_colors_by; } if(blue_fill <= blue_high_lim) { blue_fill += (frame_rate/blue_ratio)/slow_colors_by; } if (green_fill <= green_high_lim) { green_fill += (frame_rate/green_ratio)/slow_colors_by; } } stroke(red_fill,green_fill,blue_fill,alpha_fill); } void Get_Bez_Points() { //caclulate two new points between the endpoints from which //to base your besier curve points y_mid1 = (y+y2)/bez_ratio; x_mid1 = (x+x2)/bez_ratio; //point two optional for experimentation y_mid2 = (y+y2)/(bez_ratio/2); x_mid2 = (x+x2)/(bez_ratio/2); //calculate a degree point away from the current line from origin y_bez1 = (Radius/bez_amp) * sin(cur_angle-bez_angle) + y; x_bez1 = (Radius/bez_amp) * cos(cur_angle-bez_angle) + x; //calculate a degree point away from a point farther down y_bez2 = (Radius/bez_amp) * sin(cur_angle+bez_angle) + y_mid1; x_bez2 = (Radius/bez_amp) * cos(cur_angle+bez_angle) + x_mid1; } // Safely close the sound engine upon Browser shutdown. public void stop(){ Sonia.stop(); super.stop(); }