void Page::setNormHandAt(ofPoint _hand, float lerpPct){ if ( hand != _hand ){ hand.x = ofLerp(hand.x, _hand.x, lerpPct ); hand.y = ofLerp(hand.y, _hand.y, lerpPct ); bChange = true; } }
//-------------------------------------------------------------- void Page::preDraw() { ofPushMatrix(); ofPoint currPos; currPos.x = ofLerp(startPos.x, pos.x, tornadoAmount); currPos.y = ofLerp(startPos.y, pos.y, tornadoAmount); currPos.z = ofLerp(startPos.z, pos.z, tornadoAmount); ofTranslate(currPos); // sway ofTranslate(swayPos); ofRotate(RAD_TO_DEG * (swayAngle + M_PI / 2), 0, 0, 1); // flip ofRotate(RAD_TO_DEG * flipAngle, 0, 0, 1); // vert bend ofTranslate(0, vertOffsetY); ofRotate(vertAngle, 1, 0, 0); // twirl ofRotate(RAD_TO_DEG * twirlAngle, 0, 1, 0); // tilt ofRotate(RAD_TO_DEG * tiltAngle, 1, 0, 1); // align ofRotate(RAD_TO_DEG * alignAngle * alignAmount, alignPivot.x, alignPivot.y, alignPivot.z); }
ofVec3f testApp::startAnimationCameraPosition() { float smoothnessFactor=35*SpiralPoints[700*cameraindex].z +1.6*combinedImageObjects[numberofImages-cameraindex].theloadedimage.getHeight(); float timeInterval=smoothnessFactor/1500; if(startAnimationCounter<=smoothnessFactor-timeInterval) { tweenvalue = (startAnimationCounter) /smoothnessFactor; if(tweenvalue<0.98) startAnimationCounter+=timeInterval; else startAnimationCounter+=(timeInterval); overshotCameraStartingPosition=tweenedCameraPosition; } //else isstartingAnimationActive=false; else {startAnimationCounter=0; startoverShotCameraAnimation=true; } tweenedCameraPosition.x=ofLerp(0, 0 , tweenvalue); tweenedCameraPosition.y=ofLerp(0, 0, tweenvalue); tweenedCameraPosition.z=ofLerp(0, 35*SpiralPoints[700*cameraindex].z +21.6*combinedImageObjects[numberofImages-cameraindex].theloadedimage.getHeight(), tweenvalue); return tweenedCameraPosition; }
//------------------------------------------------------------- void camApp::riseFallUpdate(){ bSlowDown = false; for(int i = 0; i < nodes.size(); i++){ nodes[i]->checkState(myPerson.pos.x, myPerson.pos.y, myPerson.pos.z); if( nodes[i]->shouldPersonWait() ){ bSlowDown = true; } } //TODO: make this escapable by allowing people to move out of the node! if( percentOver >= 1.0 ){ bSlowDown = true; } if( bSlowDown ){ dragAmnt = ofLerp(dragAmnt, 0.75, 0.2); updateSpeed = ofLerp(updateSpeed, 0.06, 0.25); }else{ dragAmnt = ofLerp(dragAmnt, 1.0, 0.2); updateSpeed = ofLerp(updateSpeed, 1.0, 0.05); } }
ofVec3f testApp::adjustoverShotCameraPosition() { float smoothnessFactor=35*SpiralPoints[700*cameraindex].z +1.6*combinedImageObjects[numberofImages-cameraindex].theloadedimage.getHeight(); float timeInterval=smoothnessFactor/500; // cout<<"smoothness factor\n"<<smoothnessFactor; if(startAnimationCounter<=smoothnessFactor-timeInterval) { cout<<"\nCamera Position"<< tweenedCameraPosition.z; tweenvalue = (startAnimationCounter) /smoothnessFactor; if(tweenvalue<0.98) startAnimationCounter+=timeInterval; else startAnimationCounter+=(timeInterval); } else {isstartingAnimationActive=false;startoverShotCameraAnimation=false;} tweenedCameraPosition.x=ofLerp(0, 35*SpiralPoints[700*cameraindex].x, tweenvalue); tweenedCameraPosition.y=ofLerp(0, 35*SpiralPoints[700*cameraindex].y, tweenvalue); tweenedCameraPosition.z=ofLerp(overshotCameraStartingPosition.z, 35*SpiralPoints[700*cameraindex].z +1.6*combinedImageObjects[numberofImages-cameraindex].theloadedimage.getHeight(), tweenvalue); return tweenedCameraPosition; }
ofPoint LedStrip::getLedPosition(int led){ float ledX = ofLerp(start.x, end.x, led / (float)ledCount); float ledY = ofLerp(start.y, end.y, led / (float)ledCount); return ofPoint(ledX,ledY); }
void ofApp::updateMesh(ofMesh* mesh, ofMesh* MeshOut) { for (int i=0; i<mesh->getNumVertices(); i++) { auto vertex = mesh->getVertex(i); auto normal = mesh->getNormal(i); // calc noise distortion auto noiseVert = vertex / noiseInDiv; if (isNoiseFromNormal) { // use normals noiseVert = MeshOut->getNormal(i) / noiseInDiv; // Sydney Opera House float scalar = i % noiseVertMod; noiseVert = ofVec3f(scalar, scalar, scalar) * noiseInDiv; } // simplex noise creates uneven shapes float noise = ofNoise(noiseVert.z*noiseIn.get().z, noiseVert.x*noiseIn.get().x, noiseVert.y*noiseIn.get().y) -0.5; // sin multiplier gives more even lumps //noise = sin(noiseVert.z*noiseIn.get().x) * sin(noiseVert.x*noiseIn.get().y) * sin(noiseVert.y*noiseIn.get().z); // cos multiplier gives more even lumps //noise = cos(noiseVert.z*noiseIn.get().x) * cos(noiseVert.x*noiseIn.get().y) * cos(noiseVert.y*noiseIn.get().z); // threshold for square shapes //if (noise > 0.2) noise = 0.5; //if (noise < -0.2) noise = -0.5; auto nextVertex = vertex += normal * (noise * noiseOutMult); auto lastVert = MeshOut->getVertex(i); vertex.x = ofLerp(lastVert.x, nextVertex.x, 0.1); vertex.y = ofLerp(lastVert.y, nextVertex.y, 0.1); vertex.z = ofLerp(lastVert.z, nextVertex.z, 0.1); // update vert MeshOut->setVertex(i, vertex); } }
//-------------------------------------------------------------- void ofApp::draw() { ofBackground(255); if(debugMode) { ofSetColor(0); // draw a vector field for the debug screen for(int i = 0; i < width; i += step) { for(int j = 0; j < height; j += step) { ofVec2f field = getField(ofVec2f(i, j)); ofPushMatrix(); ofTranslate(i, j); ofSetColor(0); ofDrawLine(0, 0, ofLerp(-windSpeed, windSpeed, field.x), ofLerp(-windSpeed, windSpeed, field.y)); ofPopMatrix(); } } // draw the points as circles ofSetColor(ofColor::red); for(int i = 0; i < nPoints; i++) { ofDrawCircle(points[i], 2); } } else { // when not in debug mode, draw all the points to the screen ofSetColor(0, 10); cloud.draw(); } ofDrawBitmapStringHighlight("click to reset\nhit any key for debug", 10, 10, ofColor::white, ofColor::black); }
void Subdivision::update() { int r, g, b; if (parent == NULL) return; if (parent->horizontal) { x = parent->x + (topleft ? 0.0 : parent->width * parent->ratio); y = parent->y; width = parent->width * (topleft ? parent->ratio : 1.0 - parent->ratio); height = parent->height; } else { y = parent->y + (topleft ? 0.0 : parent->height * parent->ratio); x = parent->x; width = parent->width; height = parent->height * (topleft ? parent->ratio : 1.0-parent->ratio); } if (*isLerp) { r = ofClamp(ofLerp(255 * color->r, 255 * parent->color->r + 255 * varColor->r * 0.2 * offset.x, 0.2), 0, 255); g = ofClamp(ofLerp(255 * color->g, 255 * parent->color->g + 255 * varColor->g * 0.2 * offset.y, 0.2), 0, 255); b = ofClamp(ofLerp(255 * color->b, 255 * parent->color->b + 255 * varColor->b * 0.2 * offset.z, 0.2), 0, 255); } else { r = 255 * parent->color->r + 255 * varColor->r * offset.x; g = 255 * parent->color->g + 255 * varColor->g * offset.y; b = 255 * parent->color->b + 255 * varColor->b * offset.z; } color->set(ofColor(r, g, b, 255)); }
Lights::Lights( int x, int y, int w, int h, int r){ bActive = false; whichLight = 1; ofSetCircleResolution(100); int index=0; // top for (int i=0; i < 10; i++ ){ ofVec2f p = ofVec2f(ofLerp( (float) x + r*2, (float)x + r + (w-r),(float)i/10.0f), y); points.push_back(p); index++; } // right for (int i=0; i < 8; i++ ){ ofVec2f p = ofVec2f(x + w, ofLerp( (float) y + r*2, (float) y + r + (h-r),(float)i/8.0f) ); points.push_back(p); index++; } // bottom for (int i=0; i < 11; i++ ){ ofVec2f p = ofVec2f(ofLerp( (float)x + r + (w-r), (float) x + r*2, (float)i/10.0f), y + h); points.push_back(p); index++; } // left for (int i=0; i < 8; i++ ){ ofVec2f p = ofVec2f(x, ofLerp((float) y + r + (h-r), (float) y + r *2, (float)i/8.0f)); points.push_back(p); index++; } }
void lineOsc::update() { for (int i = 0; i < lineObjs.size(); i++) { float t = ofMap(sin(TWO_PI * ofGetFrameNum() / lineObjs[i].frequency), -1, 1, 0, 1); lineObjs[i].position.x = ofLerp(lineObjs[i].start.x, lineObjs[i].end.x, t); lineObjs[i].position.y = ofLerp(lineObjs[i].start.y, lineObjs[i].end.y, t); for (int j = 0; j < lineObjs.size(); j++) { if(j != i && lineObjs[i].playing == false) { float ac = ofDist(lineObjs[j].start.x, lineObjs[j].start.y, lineObjs[i].position.x, lineObjs[i].position.y); float cb = ofDist(lineObjs[i].position.x, lineObjs[i].position.y, lineObjs[j].end.x, lineObjs[j].end.y); float ab = ofDist(lineObjs[j].start.x, lineObjs[j].start.y, lineObjs[j].end.x, lineObjs[j].end.y); if (abs((ac + cb) - ab) <= 1.0) { //Wave Object i collided with the string of Wave Object j lineObjs[i].playing = true; int degree = (int)ofMap(i, 0, lineObjs.size(), 0, 10); trigger(degree); } } lineObjs[i].playCounter--; if(lineObjs[i].playCounter == 0) { lineObjs[i].playing = false; lineObjs[i].playCounter = PLAY_DURATION; } } } }
void Ribbon::draw() { ofPushStyle(); ofNoFill(); ofSetLineWidth(lineWidth); ofSetColor(contour->color, ofMap(abs(age - maxAge * 0.5), 0, maxAge * 0.5, maxAlpha, 0)); ofBeginShape(); for (int i = 0; i < points.size(); i++) { if (match) { idxMatched = floor(contour->points.size() * lookupMatched[i]); points[i].x = ofLerp(points[i].x, contour->points[idxMatched].x + margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 5), lerpRate); points[i].y = ofLerp(points[i].y, contour->points[idxMatched].y + margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 10), lerpRate); } else { points[i].x = ofLerp(points[i].x, contour->points[lookup[i]].x + margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 5), lerpRate); points[i].y = ofLerp(points[i].y, contour->points[lookup[i]].y + margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 10), lerpRate); } curved ? ofCurveVertex(points[i].x, points[i].y) : ofVertex(points[i].x, points[i].y); } ofEndShape(); ofPopStyle(); }
ofVec2f testApp::blob_to_data(ofxCvBlob &blob, int which) { ofPoint cent = blob.centroid; float in_x, in_y; float tgt_x, tgt_y; in_x = cent.x; in_y = kinect.getHeight() - blob.boundingRect.getMinY(); //not enough change if (abs(in_x - prev_points[which].x) < blob_eps && abs(in_y - prev_points[which].y) < blob_eps) { tgt_x = prev_points[which].x; tgt_y = prev_points[which].y; return(ofVec2f(0.0, 0.0)); } tgt_x = ofLerp(prev_points[which].x, in_x, 0.8); tgt_y = ofLerp(prev_points[which].y, in_y, 0.8); prev_points[which].x = tgt_x; prev_points[which].y = tgt_y; tgt_x /= (float)kinect.getWidth(); tgt_y /= (float)kinect.getHeight(); return(ofVec2f(tgt_x, tgt_y)); }
void ofApp::update() { if(ofGetKeyPressed('1')) { ofSeedRandom(0); for(int i = 0; i < mesh.getNumVertices(); i++) { ofVec3f point = mesh.getVertex(i); point*=1.001; point+=ofVec3f(ofRandomf(), ofRandomf(), ofRandomf()); mesh.setVertex(i, point); } } if(ofGetKeyPressed('2')) { for(int i = 0; i< referenceMesh.getNumVertices(); i++) { ofVec3f refpoint = referenceMesh.getVertex(i); ofVec3f point = mesh.getVertex(i); float increment=1-.3; float lerpX = ofLerp(refpoint.x, point.x, increment); float lerpY = ofLerp(refpoint.y, point.y, increment); float lerpZ = ofLerp(refpoint.z, point.z, increment); ofVec3f move(lerpX, lerpY, lerpZ); ofColor cur = referenceMesh.getColor(i).lerp(mesh.getColor(i), increment); mesh.setColor(i, cur); mesh.setVertex(i, move); } } }
//----------------------------------------------------------------------------------------- // void ofApp::update() { // Update time, this let's us hit space and slow down time, even reverse it. if( ofGetKeyPressed(' ') ) { timeStep = ofLerp( timeStep, ofMap( ofGetMouseX(), 0, ofGetWidth(), -(1.0f/60.0f), (1.0f/60.0f) ), 0.1f );} else { timeStep = ofLerp( timeStep, 1.0f / 60.0f, 0.1f ); } time += timeStep; }
void CirclePainter::update() { //interpolate current into wanted _radius.value = ofLerp(_radius.value, _radius.target, _radius.changeRate); _radius.target = ofLerp(_radius.target, _radius.init, _radius.changeRate); _theta = _tempo.getBarProgress() * TWO_PI; }
void GuiRangeSliderBase::update() { if (lerpFrame < lerpNumFrames) { setValueLow(ofLerp(lerpPrevLow, lerpNextLow, (float) lerpFrame / (lerpNumFrames-1))); setValueHigh(ofLerp(lerpPrevHigh, lerpNextHigh, (float) lerpFrame / (lerpNumFrames-1))); lerpFrame++; } }
void Graph::addSample(float sample) { noData = false; if(!buffer.empty() && (upSmoothing != 0 || downSmoothing != 0)) { if(sample > buffer.back()) { sample = ofLerp(sample, buffer.back(), upSmoothing); } else { sample = ofLerp(sample, buffer.back(), downSmoothing); } } if(minRange != 0 || maxRange != 0) { sample = ofClamp(sample, minRange, maxRange); } if(!buffer.empty()) { float diff = sample - buffer.back(); float cmp = bidirectional ? abs(diff) : diff; if(!derivative.empty() && derivative.back() < threshold && cmp > threshold) { lastTrigger = ofGetElapsedTimef(); triggered = true; } else { triggered = false; } derivative.push_back(abs(diff)); } buffer.push_back(sample); // could use a better datastructure to avoid resorting every sample float curThreshold = getMedian(derivative, percentile); if(threshold == 0 || threshold != threshold) { threshold = curThreshold; } else { threshold = ofLerp(curThreshold, threshold, thresholdSmoothing); } bufferPolyline = buildPolyline(buffer); derivativePolyline = buildPolyline(derivative); bufferBox = getBoundingBox(buffer); derivativeBox = getBoundingBox(derivative); if(minRange != 0 || maxRange != 0) { bufferBox.y = minRange; bufferBox.height = maxRange - minRange; buffer.back() = ofClamp(buffer.back(), minRange, maxRange); } if(bufferBox.height > FLT_EPSILON) { normalized = ofMap(buffer.back(), bufferBox.y, bufferBox.y + bufferBox.height, 0, 1); } if(derivative.size() > 0 && derivativeBox.height > FLT_EPSILON) { normalizedDerivative = ofMap(derivative.back(), derivativeBox.y, derivativeBox.y + derivativeBox.height, 0, 1); } activity = ofLerp(normalizedDerivative, activity, activitySmoothing); }
//------------------------------------------------------------------------------ void branch::update(float factor, float drawPctIn){ if( drawPct < 0.2 && drawPctIn >= 0.2 ){ if( lines.size() ){ ofPoint tipPos = lines.back().getTip(); globalSnd.play("BRANCH_GROWING", ofRandom(0.8, 0.9), 1.0, ofMap(tipPos.x, -(float)ofGetWidth()/2, (float)ofGetWidth()/2, -1, 1, true) ); } } if( ourLeafState == LEAF_DYING && leafHealthPct > 0.01 ){ leafHealthPct *= 0.98; if( leafHealthPct <= 0.01 ){ leafHealthPct = 0.0; } } if( ourLeafState == LEAF_GROWING && leafHealthPct < 1.0 ){ leafHealthPct += 0.03; if( leafHealthPct >= 1.0 ) leafHealthPct = 1.0; for(int i = 0; i < lines.size(); i++){ for(int k = 0; k < lines[i].leafs.size(); k++){ if( lines[i].leafs[k].visible == false ){ lines[i].leafs[k].visible = true; } lines[i].leafs[k].shrink = ofLerp(lines[i].leafs[k].shrink, 1.0, 0.1); } } } if( lines.size() && level == 0 && drawPctIn >= 1.0){ if( leafHealthPct < 0.7 && ourLeafState == LEAF_DYING ){ updateAngle(270); for(int i = 0; i < children.size(); i++){ children[i].updateAngle(270); } } } drawPct = drawPctIn; for(int i = 0; i < lines.size(); i++){ lines[i].update(factor, leafHealthPct); lines[i].scale = powf(ofClamp(drawPct*4, 0, 1), 0.2); if( leafHealthPct > 0.3 && ourLeafState != LEAF_DYING ){ lines[i].restoreAngleToTarget(); } } for(int k = 0; k < children.size(); k++){ children[k].update(factor, MAX(0, ofLerp(children[k].drawPct, drawPct-1.0, 0.1)) ); } }
void froebelContainer::update(){ bgColor.update(); slider.x = x; if (bEnable){ // Adjust the size // if (totalBoxHeight != height) height = ofLerp(height, totalBoxHeight, damp); // Recalculate the totalLenght of the elements // totalLenght = 0; for(int i = 0; i < elements.size(); i++){ totalLenght += elements[i]->height; } if (totalLenght > height){ ofPoint mouse = ofPoint(ofGetMouseX(),ofGetMouseY()); // Scrolling // if ( inside(mouse) ){ // if ( bCheckList || (getSelected().size() == 0) ){ float offsetPct = ofMap(mouse.y-y, 0,height,0.0,1.0,true); float diff = totalLenght - height; offsetY = ofLerp(offsetY, -diff * offsetPct, damp); // Slider Scrolling // slider.y = y + ofMap(offsetY,0,-totalLenght,0,height); slider.height = (height/totalLenght)*height; // } } } float previusY = 0; for(int i = 0; i < elements.size(); i++){ elements[i]->x = x ; elements[i]->y = y + previusY + offsetY; elements[i]->width = width; elements[i]->update(); previusY += elements[i]->height; } } else { if (totalBoxHeight != height) height = ofLerp(height, 0.0, damp); } }
//-------------------------------------------------------------- void ofxUIMovingGraphThreshold::setThreshold(float _value) { m_thresholdValue = _value; if (m_thresholdValue<getMin()){ ofLog()<< "setting thresold to mid range (value too low)"; m_thresholdValue = ofLerp(getMin(),getMax(),0.5f); } else if (m_thresholdValue>getMax()){ ofLog()<< "setting thresold to mid range (value too high)"; m_thresholdValue = ofLerp(getMin(),getMax(),0.5f); } }
void ofApp::update(){ // particle collision detection for(std::size_t i = 0; i < numNodes; i++){ particles[i].update(); if(particles[i].position.x > cageSize || particles[i].position.x < 0) { particles[i].velocity.x *= -1.0; } if(particles[i].position.y > cageSize || particles[i].position.y < 0) { particles[i].velocity.y *= -1.0; } if(particles[i].position.z > cageSize || particles[i].position.z < 0) { particles[i].velocity.z *= -1.0; } } //attractor noise and collision detection t = ofGetFrameNum() * timeSpeed; // time value for noiseField ofPoint field = noiseField(attractorCenter); float speed = (1 + ofNoise(t, field.x, field.y)) / speedLim; attractorCenter.x += ofLerp(-speed, speed, field.x); attractorCenter.y += ofLerp(-speed, speed, field.y); if(attractorCenter.x > cageSize || attractorCenter.x < 0) { attractorCenter.x = ofGetWidth()/2; } if(attractorCenter.y > cageSize || attractorCenter.y < 0) { attractorCenter.y = ofGetHeight()/2; } // normalize volume input if(!soundP){ scaledVol = ofMap(sqrt(smoothedVol), 0.0, 0.412, 0.0, 1.0, true); } // for SoundPlayer get levels if (soundP) { float * val = ofSoundGetSpectrum(1); scaledVol = val[0]*10; } }
void measureCamFps(){ float timeDiff = ofGetElapsedTimef()-lastTime; lastTime = ofGetElapsedTimef(); float curFps = 1.0/ofClamp(timeDiff, .01, 1000); camFps = ofLerp(curFps, camFps, .95); }
void echoBackChanger::update() { if(!isTransitionFinished) { backOpacity = ofLerp(backOpacity,FULL_TRANSPARENT,lerpSpeed); if(backOpacity < FULL_TRANSPARENT + THRESHOLD) { backOpacity = FULL_VISIBLE; currentImageNumber = nextImageNumber; if(currentImageNumber == images.size() - 1) nextImageNumber = 0; else nextImageNumber = nextImageNumber + 1; isTransitionFinished = true; isTimerBegan = false; } } else { if(!isTimerBegan) { timer->beginCountdown(); isTimerBegan = true; } timer->update(); if(timer->getCompleteness()) nextBackground(); } }
void update() { if( goFullscreen == 2 ){ ofSetFullscreen(false); ofSetWindowPosition(1920, 0); } if( goFullscreen == 4 ){ ofSetFullscreen(true); ofViewport(ofGetNativeViewport()); } goFullscreen++; if(goFullscreen > 4 && ofGetWindowPositionX() < 1440) { goFullscreen = 0; } renderTimer.tick(); while(osc.hasWaitingMessages()) { ofxOscMessage msg; osc.getNextMessage(&msg); if(msg.getAddress() == "/lookAngle/set") { targetLookAngle = msg.getArgAsFloat(0); } if(msg.getAddress() == "/lookAngle/add") { targetLookAngle += msg.getArgAsFloat(0); ofLog() << "targetLookAngle: " << targetLookAngle; } if(msg.getAddress() == "/screenshot") { saveScreen("button/"); } } lookAngle = ofLerp(lookAngle, targetLookAngle, .1); if(screenshotTimer.tick()) { // saveScreen("automatic/"); // uncomment to enable automatic screenshot } }
void testApp::drawLife(int id) { Player& player = players[id]; ofEnableAlphaBlending(); if(player.life > 0) { ofSetColor(255, 255); } else { ofSetColor(255, 64); } ofPushMatrix(); ofVec2f position = player.position; ofTranslate(ofLerp(position.x, ofGetWidth() / 2, panel.getValueF("lifecenter")), position.y + panel.getValueF("lifey")); int w = heartFull.getWidth(); float scale = ofMap(player.life, 0, Player::maxLife, 1., .3); ofScale(scale, scale); ofPushMatrix(); ofScale(8, 8); string name = "PLAYER " + ofToString(id + 1); ofDrawBitmapString(name, -4. * name.size(), -4); ofPopMatrix(); ofTranslate(-w * Player::maxLife / 2., 0); for(int i = 0; i < Player::maxLife; i++) { if(i < player.life) { heartFull.draw(0, 0); } else { heartEmpty.draw(0, 0); } ofTranslate(w, 0); } ofPopMatrix(); ofDisableAlphaBlending(); }
//-------------------------------------------------------------- void ofApp::audioIn(ofSoundBuffer & buffer){ // modified from audioInputExample float rms = 0.0; int numCounted = 0; for (int i = 0; i < bufferSize; i++){ float leftSample = buffer[i * 2] * 0.5; float rightSample = buffer[i * 2 + 1] * 0.5; rms += leftSample * leftSample; rms += rightSample * rightSample; numCounted += 2; } rms /= (float)numCounted; rms = sqrt(rms); // rms is now calculated vol = rms; smoothedVol *= 0.93; smoothedVol += 0.07 * vol; threshold = ofLerp(threshold, minimumThreshold, decayRate); if(rms > threshold) { // onset detected! threshold = rms; bOnSet = true; }else{ bOnSet = false; } }
//-------------------------------------------------- float ofPolyline::getAngleAtIndexInterpolated(float findex) const { if(points.size() < 2) return 0; int i1, i2; float t; getInterpolationParams(findex, i1, i2, t); return ofLerp(getAngleAtIndex(i1), getAngleAtIndex(i2), t); }
void ofxMarsyasNetwork::threadedFunction() { while( isThreadRunning() ) { if (priority != targetPriority) { run(); priority = targetPriority; } // cout << "ofxMarsyasNetwork trying to lock" << endl; if (lock()) { // cout << "ofxMarsyasNetwork in lock" << endl; tick(); thisTick = ofGetSystemTime(); rate = ofLerp(rate, 1000.0/(thisTick-lastTick), 0.001); lastTick = thisTick; update(); unlock(); // cout << "ofxMarsyasNetwork after unlock()" << endl; } else { // cout << "ofxMarsyasNetwork sleeping" << endl; ofSleepMillis(20); } if (targetRate>0) ofSleepMillis(1000.0/targetRate); } }
void checkList::update(){ // Calculate the total height of addons elements // float totalLenght = 0; for(int i = 0; i < elements.size(); i++){ totalLenght += elements[i]->height; } float offSetY = 0; if (title != ""){ offSetY += elementHeight; } ofRectangle rect = *this; if (title != ""){ rect.y += elementHeight*2.0; rect.height -= elementHeight*2.5; } if (inside(ofGetMouseX(),ofGetMouseY()) && totalLenght > rect.height){ float pct = ofMap(ofGetMouseY()-rect.y, 0, rect.height, 0,1,true); float diff = totalLenght - rect.height; mouseOffSet = ofLerp( mouseOffSet, -diff * pct, damp); } for(int i = 0; i < elements.size(); i++){ elements[i]->x = x; elements[i]->y = y + offSetY + mouseOffSet; elements[i]->width = width; offSetY += elements[i]->height; } }