void drawBranch(float x, float y, float radius, int level) { path.clear(); path.setStrokeColor(ofColor::blueSteel); path.setStrokeWidth(level*2); path.arc(x,y, radius,radius, -180, 0); path.draw(); ofFill(); ofSetColor(56); ofCircle(x, y, level*3); if (level > 0 ){ drawBranch(x-radius, y+radius/2, radius/2, level-1); drawBranch(x+radius, y+radius/2, radius/2, level-1); } // return drawBranch(x, y, radius, level); }
//-------------------------------------------------------------- void testApp::update(){ /* get the spectral data */ float * val = ofSoundGetSpectrum(nBandsToGet); for (int i = 0; i < nBandsToGet; i++){ // let the smoothed calue sink to zero: fftSmoothed[i] *= 0.96f; // take the max, either the smoothed or the incoming: if (fftSmoothed[i] < val[i]) fftSmoothed[i] = val[i]; if (fftSmoothed[i] > fftmax) { fftmax = fftSmoothed[i]; } } /* update our bark map'd frequency bins */ memset(bins, 0x00, sizeof(bins)); for (int i = 0; i < SPECTRAL_BANDS; i++) { int idx = barkmap[i]; bins[idx] += fftSmoothed[i] * 20; } /* put the eq vals into a path to turn them into a curve */ int line_len = fbo_res; float ppseg = line_len /(float)(BARK_MAX+1); eq_path.clear(); eq_path.curveTo(0, -bins[0]); for (int i = 0; i < BARK_MAX; i++) { // bins[i] = max(5.0f, bins[i]); //set a lower bound on the bin val eq_path.curveTo(i * ppseg, -bins[i]); } // eq_path.curveTo(BARK_MAX * ppseg, -bins[0]); // eq_path.curveTo(BARK_MAX * ppseg, -bins[0]); //smooth this out a little at the end so the eq texture wraps, 25 = BARK_MAX eq_path.curveTo(25 * ppseg, -(bins[0] + bins[24] + bins[23] + bins[22])/4.0f); eq_path.curveTo(26 * ppseg, -bins[0]); eq_path.curveTo(26 * ppseg, -bins[0]); ofMesh eq_m = eq_path.getTessellation(); //load up the eq curve into a texture eq_tex.loadData((float *)eq_m.getVerticesPointer(), fbo_res, 1, GL_RGB); //update where on the axis we will apply the latest eq data axis_loc--; if (axis_loc < 0) axis_loc = fbo_res; //use fbo to work out displacement coeffcients posbuf.dst->begin(); ofClear(0); pos_shader.begin(); pos_shader.setUniformTexture("u_prevDisp", posbuf.src->getTextureReference(), 0); pos_shader.setUniformTexture("u_newDisp", eq_tex, 1); //pass the new displacement data pos_shader.setUniform1f("u_axisloc", axis_loc); pos_shader.setUniform1f("u_decayRate", posdecayrate); ofSetColor(255, 255, 255, 255); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3f(0, 0, 0); glTexCoord2f(fbo_res, 0); glVertex3f(fbo_res, 0, 0); glTexCoord2f(fbo_res, fbo_res); glVertex3f(fbo_res, fbo_res, 0); glTexCoord2f(0, fbo_res); glVertex3f(0, fbo_res, 0); glEnd(); pos_shader.end(); posbuf.dst->end(); posbuf.swap(); }