void VideoBuffer::setFramePos(float posPerc) { float outVal = posPerc * (float)(size()-1); // convert percentage to numFrames float tempVal = floor(outVal+0.5); // used to round float to next int if(tempVal==lastVal){ framePos = tempVal+1; // If the percenatge to frames = name int as last time +1 //cout << "frames Pos = " << framePos << " --- " << "lastVal = " << lastVal << " --- " << "tempVal + 1 = " << tempVal + 1; } else if(tempVal-lastVal==1){ framePos = tempVal; // else use the rounded value //cout << "frames Pos = " << framePos << " --- " << "lastVal = " << lastVal << " --- " << "tempVal = " << tempVal; } else { framePos = outVal; // else percentage to frame converstion was correct //cout << "frames Pos = " << framePos << " --- " << "lastVal = " << lastVal << " --- " << "outVal = " << outVal; } // If the audio rec position conversion is greater than a single frame, or if the framerate changes // work out the dirreference and paste the previous frame accross to avoid all glitches :) int diff = ofWrap(framePos-lastVal, 0, size()); if(diff>1 && lastVal <= framePos){ for(int i = lastVal; i < lastVal+diff; i++){ // cout << "FRAMEPOS = " << framePos << " -- " << "LAST VAL = " << lastVal << " -- " << "DIFF = " << diff << " -- " << "LAST VAL + DIFF = " << lastVal+diff << " -- " << "framePos - lastVal = " << framePos - lastVal << endl; frames[ofWrap(i,0,size())] = frames[lastVal]; } } lastVal = framePos; // Store the last truncated integer }
void Lyu::ArcBarNode::customDraw() { if(TimeStart<=0) { TimeStart = ofGetElapsedTimef(); return; } float TimeNow = ofGetElapsedTimef(); float PassedTime = TimeNow-TimeStart; float TimeNorm = StartPct+PassedTime/Duration; float pct(0); if(WMode==WrapMode::CLAMP) { pct = ofClamp(TimeNorm,0,1); } else if(WMode==WrapMode::REPEAT) { pct = ofWrap(TimeNorm,0,1); } else if(WMode==WrapMode::MIRRORED_REPEAT) { pct = ofWrap(TimeNorm,0,2); pct = pct>1.0f?2.0f-pct:pct; } float deg = pct*360.0f; ofPath P; float degStep = 360.0f/CircleRes; int IterNum = ceil(deg/degStep); float degStep2 = deg/IterNum; for(int i=0;i<=IterNum;i++) { float rad = ofDegToRad(degStep2*i); float x = Radius[0]*cos(rad); float y = Radius[0]*sin(rad); P.lineTo(ofVec2f(x,y)); } for(int i=IterNum;i>=0;i--) { float rad = ofDegToRad(degStep2*i); float x = Radius[1]*cos(rad); float y = Radius[1]*sin(rad); P.lineTo(ofVec2f(x,y)); } P.lineTo(ofVec2f(Radius[0],0)); P.setColor(Cr); ofPushStyle(); ofFill(); P.draw(); ofPopStyle(); }
SharedPtrColVec ComplimentaryPalette::createPalette(const ofColor & _seedColour) { seedColour = _seedColour; vector<float> hues; // stores the hue values float ang = seedColour.getHueAngle(); // hue angle of the seed colour float s = seedColour.getSaturation(); float b = seedColour.getBrightness(); ang = ofMap(ang, 0, 360, 0, 255); // map from angle to HSB colour space min and max. float compHue = ofWrap(ang + 127.5, 0, 255); // The complimentary hue's colour. colours->push_back( ofColor::fromHsb( ang, s, b ) ); colours->push_back( ofColor::fromHsb( ang, ofWrap(s + 15, 0, 255), ofWrap(b + 15, 0, 255) ) ); colours->push_back( ofColor::fromHsb( ang, ofWrap(s - 15, 0, 255), ofWrap(b - 15, 0, 255) ) ); colours->push_back( ofColor::fromHsb( compHue, ofWrap(s + 15, 0, 255), ofWrap(b + 15, 0, 255) ) ); colours->push_back( ofColor::fromHsb( compHue, ofWrap(s - 15, 0, 255), ofWrap(b - 15, 0, 255) ) ); return colours; }
void ConnectionTracerRenderer ::drawTracer(const AbstractConnection& connection, std::shared_ptr<ofBaseRenderer>& renderer) { if (!connection.visible()) { return; } auto ratio = ofWrap(_rawRatio + static_cast<float>(connection.entityId() % 12) / 12.0f, 0, 1); auto tracerPos = connection.evaluatePosition(ratio); const auto& entityA = connection.sourceEntity(); const auto& entityB = connection.targetEntity(); auto color = getInterpolated(entityA.color(), entityB.color(), ratio); color.setBrightness(color.getBrightness() * 1.2); color.a *= getInterpolated(entityA.alpha(), entityB.alpha(), ratio); color.a *= _params.alphaFade.evaluate(ratio); renderer->setColor(color); renderer->drawBox(tracerPos, _params.drawRadius.get()); }
float ofWrapDegrees(float angle, float from, float to){ return ofWrap(angle, from, to); }
//-------------------------------------------------- float ofWrapRadians(float angle, float from, float to){ return ofWrap(angle, from, to); }
//---------------------------------------------------------- // wraps any radian angle -FLT_MAX to +FLT_MAX into 0->2PI range. // TODO, make angle treatment consistent across all functions // should always be radians? or should this take degrees? // used internally, so perhaps not as important float ofPolyline::wrapAngle(float angleRadians) { return ofWrap(angleRadians, 0.0f, TWO_PI); }
void ofApp::keyPressed(int key){ if(key>='0' && key<='9'){ cycle_disp_mode = int(key)-48; cout<<"cycle display mode: "<<cycle_disp_mode<<endl; } if(key=='a'){ mute = !mute; } /* if(key=='b'){ disp_buf = ofWrap(disp_buf+1, 0, 3); cout<<"display buffer: "<<disp_buf<<endl; }*/ if(key=='c'){ draw_offset.x = draw_offset.y = 0; } if(key=='d'){ disp_mode = (disp_mode+1)%display_sequence.size(); cout<<"display mode: "<<disp_mode<<endl; } if(key=='f'){ fullscreen = !fullscreen; ofSetFullscreen(fullscreen); } if(key=='h'){ usage(); } if(key=='i'){ integrator = 1-integrator; cout<<"integrator: "<<integrator<<endl; } if(key=='l'){ /*cout<<"reload shaders"<<endl; loadShaders(); */ } if(key=='p'){ disp_scale = ofWrap(disp_scale+1, 0, num_scales); cout<<"display scale: "<<disp_scale<<endl; } if(key=='s'){ save_frame = true; } if(key=='r'){ forward_graph->initFbos(); vwt->scramble(); } if(key==']'){ setResolution(fbo_params.width*2, fbo_params.height*2); cout<<"new resolution: "<<fbo_params.width<<" by "<<fbo_params.height<<endl; } if(key=='['){ if(fbo_params.width>1 && fbo_params.height>1) setResolution(fbo_params.width/2, fbo_params.height/2); cout<<"new resolution: "<<fbo_params.width<<" by "<<fbo_params.height<<endl; } if(key=='n'){ //for testing purposes setResolution(fbo_params.width, fbo_params.height); cout<<"call setResolution() with current resolution"<<endl; } if(key=='m'){ toggleRenderMode(); } if(key=='v'){ toggleVideoRecord(); } }
//-------------------------------------------------------------- void testApp::update() { ofBackground(ofColor::black); // grab new frame and update colorImg with it. bool bNewFrame = false; #ifdef _USE_LIVE_VIDEO vidGrabber.update(); bNewFrame = vidGrabber.isFrameNew(); #else vidPlayer.update(); bNewFrame = vidPlayer.isFrameNew(); #endif if (bNewFrame) { #ifdef _USE_LIVE_VIDEO colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); #else colorImg.setFromPixels(vidPlayer.getPixels(), 320,240); #endif grayImage = colorImg; // converts from color to greyscale float time = ofGetElapsedTimef(); // Update mesh from grayImage's pixels updateMesh(); // update a few variables based on time float timeToChangePalettes = 10.0f; int paletteIndex = (int) ((ofWrap( time, 0.0f, timeToChangePalettes ) / timeToChangePalettes ) * palettes.size()); if( palettes.size() > 0 && paletteIndex < palettes.size()) currPalette = &palettes.at(paletteIndex); linesHeight = 80.0f; lineSkip = 4; //ofMap( cos(time * 1.1f), -1.0f, 1.0f, 2, 25 ); // if we click, wait a bit until we auto orbit the camera if( (time - lastClickTime) > 4.0 ) { float orbitLong = ofMap( ofNoise(time*0.2f), 0.0f, 1.0f, -50.0f, 50.0f ) ; float orbitLat = ofMap( ofNoise( (time+111.0f)*0.3f), 0.0f, 1.0f, 0.0f, -100.0f ) ; float orbitRadius = ofMap( ofNoise( (time-123.0f)*0.45f), 0.0f, 1.0f, 100.0f, 250.0f ) ; camera.orbit(orbitLong, orbitLat, orbitRadius ); } fbo.begin(); ofClear(0, 0, 0, 0); //clear our Fbo memory ofEnableDepthTest(); //enable 3d camera.begin(); //start our camera viewpoint ofTranslate( (grayImage.getWidth() * -0.5f) * imageToSpaceScaling.x, //move x 0.0f, //move y (grayImage.getHeight() * -0.5f) * imageToSpaceScaling.z //move z ); ofSetColor( ofColor::white ); //start with a white mesh colorFromHeightShader.begin(); //begin our shader if( currPalette != NULL ) //make sure we have a palette { //we pass our palette to the shader colorFromHeightShader.setUniformTexture( "u_paletteSampler", currPalette->getTextureReference(), 1 ); } //we pass our linesHeight to the shader colorFromHeightShader.setUniform1f("u_maxHeight", linesHeight ); //we draw our mesh (currently in OF_PRIMITIVE_LINES mode) mesh.draw(); colorFromHeightShader.end(); //stop our shader operation camera.end(); //end our camera view ofDisableDepthTest(); //ending 3d fbo.end(); //stop drawing inside the fbo } }
//-------------------------------------------------------------- void GrainPlayer::setPositionRandom(float _val){ grainPosition = ofWrap(playHead + (ofRandom(0.0,_val)),0.0,1.0); }