FFTTracer::FFTTracer(){ fft_size = ((testApp*)ofGetAppPtr())->fft_size; magnitude = new float[fft_size]; for (int i = 0; i < fft_size; i++) { ofVec3f p = ofVec3f(0, 0, 0); pos.push_back(p); ofVec3f v = ofVec3f(0, 0, 0); vel.push_back(v); Tracker *t = new Tracker; t->setup(); t->setTrackerLength(10); trackers.push_back(t); } //ばねパラメータ /* stiffness = 1.0; damping = 0.9; mass = 100.0; */ stiffness = 2.0; damping = 0.92; mass = 200; camStart = ((testApp*)ofGetAppPtr())->cam.getPosition(); camEnd = camStart; }
//-------------------------------------------------------------- void AppCore::draw() { ofBackground(140); bothKinects.draw(ofGetWidth()-bothKinects.width/4-10,10,bothKinects.width/4,bothKinects.height/4); contourFinder.draw(0, 0, ofGetWidth(), ofGetHeight()); for (int i = 0; i < TUBE_NUM; i++){ allPipes[i]->draw(); } string mText = ofToString(mPerson->pipeID) + "/f:" + ofToString(mPerson->frequency) + "/d:" + ofToString(mPerson->diameter) + "/h:" + ofToString(mPerson->height - mPerson->length); ofDrawBitmapStringHighlight(mText, ofGetAppPtr()->mouseX + 5, ofGetAppPtr()->mouseY); ofSetColor(0, 0, 0); ofDrawBitmapStringHighlight(message, 20,ofGetHeight()-40); if(outputState){ ofDrawBitmapStringHighlight("stereo audio (press a to switch)", 20, ofGetHeight()-20); }else{ ofDrawBitmapStringHighlight("8-channel audio (press a to switch)", 20,ofGetHeight()-20); } for(int i=0; i<currentInput; i++){ // draw center of blobs string pText = ofToString(i) + " " + ofToString(persons[i]->pipeID) + " " + ofToString(persons[i]->frequency); ofSetColor(255, 255, 0); ofFill(); ofCircle(persons[i]->x, persons[i]->y, 5); ofDrawBitmapStringHighlight(pText, persons[i]->x+5, persons[i]->y-5); ofSetColor(255); } }
void demoAnim::animationStepRequested() { //------- try to set the current tag for the current animation XML file if(animXML.setCurrentTag(";animation")){ //------- if the current animation step is less than the total number of steps if(animStep<animXML.getNumTag("step")){ //------- push into the tag and fetch the event Type animXML.pushTag("step",animStep); if(animXML.getCurrentTag().getAttribute("type")=="select"){ ofTag& tag=animXML.getCurrentTag(); animXML.setCurrentTag(";animation"); string whr=tag.getAttribute("where"); string which=tag.getAttribute("which"); animXML.getCurrentTag().removeNode("step",animStep); animXML.addTag(moveTag("2000",whr,"w/2","h/2"),animStep); animXML.addTag(clickDownTag(),animStep+1); animXML.addTag(clickUpTag(),animStep+2); animXML.addTag(moveTag("2000",whr,"w/2","h*"+which+".5"),animStep+3); animXML.addTag(clickDownTag(),animStep+4); animXML.addTag(clickUpTag(),animStep+5); animXML.pushTag("step",animStep); animXML.writeFile("test.xml"); } handleAnimStep(animXML.getCurrentTag()); } //-- if the animStep is greater than the current number of steps in the xml, end the animation else anim.nextEvent(OF_VMOUSE_END,ofGetAppPtr()->mouseX,ofGetAppPtr()->mouseY,0); } animStep++; }
//-------------------------------------------------------------- void aRotationGui::guiEvent(ofxUIEventArgs &e) { string name = e.widget->getName(); int kind = e.widget->getKind(); //get the track number from the name. vector<string> result=ofSplitString(name, "_"); int row = ofToInt(result[0]); if (name == ofToString("CLEAR ALL")) { ofxUILabelButton *clearBut = (ofxUILabelButton *)Rotation_gui_1->getWidget("CLEAR ALL"); if(clearBut->getValue()){ resetGUI(28, row,true); } } else if (ofIsStringInString(name, "TRK_CLR")) { ofxUIImageButton *clearBut = (ofxUIImageButton *)Rotation_gui_1->getWidget(util::dDigiter(row)+"_TRK_CLR"); if(clearBut->getValue()){ resetGUI(row,row,false); } } else if (name == ofToString(util::dDigiter(row)+"_rX")) { ofxUINumberDialer *oriX = (ofxUINumberDialer *)Rotation_gui_1->getWidget(ofToString(util::dDigiter(row)+"_rX")); ((ofApp*)ofGetAppPtr())->abcModels[row].abcOrientation.x = oriX->getValue(); } else if (name == ofToString(util::dDigiter(row)+"_rY")) { ofxUINumberDialer *oriY = (ofxUINumberDialer *)Rotation_gui_1->getWidget(ofToString(util::dDigiter(row)+"_rY")); ((ofApp*)ofGetAppPtr())->abcModels[row].abcOrientation.y = oriY->getValue(); } else if (name == ofToString(util::dDigiter(row)+"_rZ")) { ofxUINumberDialer *oriZ = (ofxUINumberDialer *)Rotation_gui_1->getWidget(ofToString(util::dDigiter(row)+"_rZ")); ((ofApp*)ofGetAppPtr())->abcModels[row].abcOrientation.z = oriZ->getValue(); } }
void SawSynth::draw(){ if (alpha > 0) { int n = ofGetWidth() / height + 1; ofSetColor(alpha); ofPushMatrix(); ofTranslate(0, phase); ofSetLineWidth(5); for (int i = -1; i < n + 1; i++) { ofLine(0, height * i, ofGetWidth(), height * i); } ofSetLineWidth(1); ofPopMatrix(); } else { switch (deleteMode) { case 1: ((testApp*) ofGetAppPtr())->saws.pop_front(); break; case 2: ((testApp*) ofGetAppPtr())->saws.pop_back(); case 0: default: break; } } }
void AirButton::draw(ofPoint orig) { ofPoint m = ofPoint(ofGetAppPtr()->mouseX-ofGetWidth()/2,ofGetHeight()/2-ofGetAppPtr()->mouseY); _orig = orig; ofSetColor(255,255,255); _img.draw(ofPoint(_orig.x+IMG_GAP, _orig.y+IMG_GAP)); if (isFocused(m)) { if (isSelected()) ofSetColor(0,255,0); else ofSetColor(0,0,255); ofNoFill(); ofDrawRectangle(_orig, _width, _height); } else if (isSelected()) { ofSetColor(0,255,0); ofNoFill(); ofDrawRectangle(_orig, _width, _height); } }
void Particle::updateInteractions(bool mousePressed, string mouseString, int pmouseX, int pmouseY) { // this is where our interaction comes in. if (mousePressed) { int mouseX = ofGetAppPtr()->mouseX; int mouseY = ofGetAppPtr()->mouseY; float distanceSquared = distPointToSegmentSquared(pmouseX,pmouseY,mouseX,mouseY,position.x,position.y); if (mouseString == "LEFT") { if (distanceSquared < mouseInfluenceSize) // remember mouseInfluenceSize was squared in setup() { // To change the velocity of our particle, we subtract that change from the lastPosition. // When the physics gets integrated (see updatePhysics()), the change is calculated // Here, the velocity is set equal to the cursor's velocity lastPosition = position - ofVec3f((mouseX-pmouseX)*mouseInfluenceScalar, (mouseY-pmouseY)*mouseInfluenceScalar); } } else // if the right mouse button is clicking, we tear the cloth by removing links { if (distanceSquared < mouseTearSize) links.clear(); } } }
void MagicLightCircle::updateOSC() { while(receiver.hasWaitingMessages()) { ofxOscMessage m; receiver.getNextMessage(&m); string address = m.getAddress(); if(mapToOfParameterFloatValue[address] != NULL) { mapToOfParameterFloatValue[address]->set(m.getArgAsFloat(0) * multipliers[address]); } if(address == "/savePreset") { ((ofApp*)ofGetAppPtr())->saveGUIPreset(); } if(address == "/changePreset") { ((ofApp*)ofGetAppPtr())->presetId = m.getArgAsInt32(0); } if(address == "/loadPreset") { ((ofApp*)ofGetAppPtr())->presetId = m.getArgAsInt32(0); ((ofApp*)ofGetAppPtr())->loadGUIPreset(m.getArgAsInt32(0)); } if(address == "/turnOnRandomLight") { turnOnRandomLight(); } if(address == "/turnOnLight") { turnOnLight(m.getArgAsInt32(0)); } if(address.find("newPoint") <= 10) { int pointPos = ofToInt(address.substr(10,1)); ofVec3f point; point.x = (m.getArgAsFloat(0) * radius * 2); point.y = (m.getArgAsFloat(1) * radius * 2); point.z = m.getArgAsFloat(2); // cout << point.z << endl; Blob tempBlob; tempBlob.point = point; tempBlob.life = MAX_DURATION_FRAMES_BLOB_WITH_NO_INTERACTION; if(pointPos+1>blobs.size()) blobs.push_back(tempBlob); else blobs[pointPos] = tempBlob; timerNoPoints = 0; } if(address == "ControlLight" && useOSC) { for(int a = 0; a < totMagicPoints; a++) { magicPoints[a]->intensity = float(m.getArgAsInt32(a))/255.0; } } } }
/*! * @brief Update */ void Stove::update() { ofPoint m = ofPoint(ofGetAppPtr()->mouseX-ofGetWidth()/2,ofGetHeight()/2-ofGetAppPtr()->mouseY); _bSelected = isFocused(m); // Update burners for (int i=0; i<_burners.size(); i++) _burners[i].update(); }
void demoAnim::drawCursor() { ofSetColor(255, 255, 255); if(anim.isPlaying()){ if(anim.isClicked()) ofSetColor(128, 128, 128); pointer.draw(anim.x-10, anim.y, pointer.width*2,pointer.height*2); ofSetColor(128,128,128,128); } pointer.draw(ofGetAppPtr()->mouseX-10, ofGetAppPtr()->mouseY, pointer.width*2,pointer.height*2); }
void Through::draw(){ ofDisableBlendMode(); ((ofApp*)ofGetAppPtr())->syphonIO.fbo.begin(); ofSetColor(255); tex.loadData(pixels); tex.draw(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); ((ofApp*)ofGetAppPtr())->syphonIO.fbo.end(); ((ofApp*)ofGetAppPtr())->syphonIO.server.publishTexture(&((ofApp*)ofGetAppPtr())->syphonIO.fbo.getTextureReference()); }
void KinectCloud::update() { // Kinect更新 ((testApp*)ofGetAppPtr())->kinect.update(); ((testApp*)ofGetAppPtr())->kinect.setCameraTiltAngle(gui.getValueI("angle")); if (((testApp*)ofGetAppPtr())->kinect.isFrameNew()) { kinectCam.setFromPixels(((testApp*)ofGetAppPtr())->kinect.getPixels(), ((testApp*)ofGetAppPtr())->kinectWidth, ((testApp*)ofGetAppPtr())->kinectHeight, OF_IMAGE_COLOR); kinectDepth.setFromPixels(((testApp*)ofGetAppPtr())->kinect.getDepthPixels(), ((testApp*)ofGetAppPtr())->kinectWidth, ((testApp*)ofGetAppPtr())->kinectHeight, OF_IMAGE_GRAYSCALE); } //ポイントクラウド記録 recordPointCloud(); //Glow glow.begin(); //ポイントクラウドの描画 drawPointCloud(); glow.end(); glow.update(); //GUI gui.update(); }
void KinectCloud::recordPointCloud() { // 画面の幅と高さ int w = ((testApp*)ofGetAppPtr())->kinectWidth; int h = ((testApp*)ofGetAppPtr())->kinectHeight; // メッシュを生成 ofMesh mesh; mesh.setMode(OF_PRIMITIVE_POINTS); // ブレンド設定 if (gui.getValueB("blend_add")) { ofEnableBlendMode(OF_BLENDMODE_ADD); } // 設定した間隔で、画面の深度情報と色を取得してメッシュの頂点に設定 int step = gui.getValueI("step"); for(int y = 0; y < h; y += step) { for(int x = 0; x < w; x += step) { if(((testApp*)ofGetAppPtr())->kinect.getDistanceAt(x, y) < gui.getValueI("thresh")) { if (gui.getValueB("pick_color")) { ofFloatColor col = ((testApp*)ofGetAppPtr())->kinect.getColorAt(x, y); //col = ofFloatColor(col.r, col.g, col.b, gui.getValueF("cloud_alpha")); //HSBを調整 ofColor tmpColor = ofColor(col.r * 255, col.g * 255, col.b * 255); float hue = tmpColor.getHue(); float sat = tmpColor.getSaturation() * gui.getValueF("color_s"); float br = tmpColor.getBrightness() * gui.getValueF("color_b"); tmpColor.setHsb(hue, sat, br); col.r = (float)tmpColor.r / 255.0; col.g = (float)tmpColor.g / 255.0; col.b = (float)tmpColor.b / 255.0; col.a = 0.9; mesh.addColor(col); } else { mesh.addColor(ofFloatColor(255,255,255)); } ofVec3f loc = ((testApp*)ofGetAppPtr())->kinect.getWorldCoordinateAt(x, y); //float rand = gui.getValueF("cloud_rand"); //loc = ofVec3f(loc.x + ofRandom(-rand, rand), loc.y + ofRandom(-rand, rand), loc.z); //loc = ofVec3f(loc.x, loc.y, loc.z + ofRandom(-rand, rand)); mesh.addVertex(loc); } } } //dequeに追加 meshs.push_back(mesh); int rec_step = gui.getValueF("rec_step"); int rec_size = gui.getValueF("rec_size"); if (meshs.size() > rec_size * rec_step) { meshs.pop_front(); } }
void FFTColor::draw(){ for (int i = 0; i < fft_size/3; i++) { magnitudeLow += powf(((testApp*)ofGetAppPtr())->magnitude[i], 0.25); } for (int i = fft_size/3; i < fft_size/3 * 2; i++) { magnitudeMid += powf(((testApp*)ofGetAppPtr())->magnitude[i], 0.25); } for (int i = fft_size/3 * 2; i < fft_size; i++) { magnitudeHigh += powf(((testApp*)ofGetAppPtr())->magnitude[i], 0.25); } float scale = 0.25; ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2); glEnable(GL_DEPTH_TEST); //glEnable(GL_CULL_FACE); ofEnableBlendMode(OF_BLENDMODE_ALPHA); for (int j = 0; j < ofGetHeight(); j += 40) { for (int i = 0; i < ofGetWidth(); i += 40) { ofPushMatrix(); ofTranslate(i, j, 0); float add = (((testApp*)ofGetAppPtr())->avg_power); float force = stiffness * -rot[i] + add; float acceleration = force / mass; vec[i] = damping * (vec[i] + acceleration); rot[i] += vec[i]; //ofRotateX(rot[i]); ofRotateX(rot[i] + i * 0.15); ofRotateY(rot[i]*1.5 + j * 0.15); //ofRotateY(rot[i]*(0.2 + i / 500.0)); //ofRotateZ(rot[j]*(0.3 + j / 500.0)); ofSetColor(magnitudeLow * scale, magnitudeMid * scale, magnitudeHigh * scale); ofBox(0, 0, 0, 30 + add * 0.8); if (add > 0) { ofNoFill(); ofEnableSmoothing(); ofSetLineWidth(2); //ofSetColor(63, 63, 63); ofSetColor(magnitudeLow * scale * 1.5, magnitudeMid * scale * 1.5, magnitudeHigh * scale * 1.5); ofBox(0, 0, 0, 30 + add * 2.0); ofFill(); ofSetLineWidth(1); ofDisableSmoothing(); } ofPopMatrix(); } } glDisable(GL_DEPTH_TEST); //glDisable(GL_CULL_FACE); ofEnableBlendMode(OF_BLENDMODE_ADD); }
void FFTFnwrGlitch::update(){ // unsigned char *pixels = fnwr.getPixels(); // ピクセルごとに処理 pixels = fnwr.getPixels(); zMax = 0; for (int i = 0; i < WIDTH; i++) { for (int j = 0; j < HEIGHT; j++) { // ピクセルノRGB値を取得 float r = (float)pixels[j * fnwr.width * 3 + i * 3] / 256.0; float g = (float)pixels[j * fnwr.width * 3 + i * 3 + 1] / 256.0; float b = (float)pixels[j * fnwr.width * 3 + i * 3 + 2] / 256.0; // RGBから明度を算出 float brightness = (r + g + b) / 3.0f; //float addZ = brightness * -100 + ((testApp*)ofGetAppPtr())->avg_power * brightness * -0.1; float addZ = ((testApp*)ofGetAppPtr())->avg_power * brightness * -8.0; float forceZ = stiffness * -myVerts[j * WIDTH + i].z + addZ; float accelerationZ = forceZ / mass; vec[i] = damping * (vec[i] + accelerationZ); myVerts[j * WIDTH + i].z += vec[i]; //float z = brightness * -100 + ((testApp*)ofGetAppPtr())->avg_power * brightness * -40; if (myVerts[j * WIDTH + i].z < zMax) { zMax = myVerts[j * WIDTH + i].z; } // 明度から頂点の位置を設定 //myVerts[j * WIDTH + i] = ofVec3f(i, j, z); // 頂点の色はカメラのピクセルの値をそのまま使用 myColor[j * WIDTH + i] = ofFloatColor(r, g, b, 1.0); } } // VBOの座標と色の情報を更新 myVbo.updateVertexData(myVerts, NUM_PARTICLES); myVbo.updateColorData(myColor, NUM_PARTICLES); camPct += 0.01; if (camPct > 1.0) { camPct = 1.0; } camCurrent = interpolateByPct(camPct, 0.3); ((testApp*)ofGetAppPtr())->cam.setPosition(camCurrent); ((testApp*)ofGetAppPtr())->cam.lookAt(ofVec3f(0,0,0)); }
FFTColor::FFTColor(){ fft_size = ((testApp*)ofGetAppPtr())->fft_size; magnitudeHigh = 0; magnitudeMid = 0; magnitudeLow = 0; magnitude = new float[fft_size]; rot = new float[fft_size]; vec = new float[fft_size]; /* stiffness = 0.8; damping = 0.9; mass = 4.0; */ stiffness = 0.1; damping = 0.5; mass = 80.0; for (int i = 0; i < fft_size; i++) { rot[i] = 0; vec[i] = 0; } }
//-------------------------------------------------------------------------- void arduinoConnect::update(){ // update the arduino, get any data or messages. for(int i=0; i<numArduinos; i++){ //cout << "udpdate for ard " << i << endl; ard[i].update(); if (ard[i].isArduinoReady()){ if(!bSetupArduino[i]){ setupArduino(i); //REsetup this arduino bSetupArduino[i] = true; } accelX[i] = ard[i].getAnalog(0); accelY[i] = ard[i].getAnalog(1); accelZ[i] = ard[i].getAnalog(2); if((((testApp*)ofGetAppPtr())->bDebug)){ //if debugging, keep value history accelXHistory[i][frameCount] = accelX[i] - 300; accelYHistory[i][frameCount] = accelY[i] - 300; accelZHistory[i][frameCount] = accelZ[i] - 370; } } else setupArduino(i); //REsetup this arduino } frameCount++; if (frameCount >= 300) frameCount = 0; }
void StKaleidoscope::setup(){ gui = new ofxUICanvas(); gui->init(212, 10, 200, 200); gui->addSpacer(); gui->addLabel("KALEIDO SCOPE"); // gui->addSlider("HUE", 0, 1.0, 0.5); gui->addSlider("SEGMENT", 0, 8.0, 3.0); gui->addSlider("NOISE AMP", 0.0, 3.0, 1.0); gui->addSlider("ZOOM", 1.0, 8.0, 2.0); gui->addSlider("SAT", 0, 2.0, 1.0); gui->addSlider("BR", 0, 2.0, 1.0); gui->addSpacer(); gui->addButton("SAVE SETTINGS", false); gui->loadSettings("StKaleidoscope.xml"); gui->autoSizeToFitWidgets(); gui->setVisible(false); ofAddListener(gui->newGUIEvent,this,&StKaleidoscope::guiEvent); post.init(ofGetWidth(), ofGetHeight()); kaleido = post.createPass<KaleidoscopePass>(); kaleido->setSegments(3.0); kaleido->setEnabled(true); noise = post.createPass<NoiseWarpPass>(); noise->setEnabled(true); noise->setFrequency(2.0); bloom = post.createPass<BloomPass>(); bloom->setEnabled(true); app = ((ofApp*)ofGetAppPtr()); }
FFTFnwrGlitch::FFTFnwrGlitch(){ fnwr.loadImage("noiz1.png"); // 頂点情報を初期化 for (int i = 0; i < WIDTH; i++) { for (int j = 0; j < HEIGHT; j++) { myVerts[j * WIDTH + i].set(i,j, 0); myColor[j * WIDTH + i].set(1.0, 1.0, 1.0, 1.0); } } // 頂点バッファに位置と色の情報を設定 myVbo.setVertexData(myVerts, NUM_PARTICLES, GL_DYNAMIC_DRAW); myVbo.setColorData(myColor, NUM_PARTICLES, GL_DYNAMIC_DRAW); /* stiffness = 10.0; damping = 0.98; mass = 1000.0; */ stiffness = 2.0; damping = 0.95; mass = 20.0; camStart = ((testApp*)ofGetAppPtr())->cam.getPosition(); camEnd = camStart; }
void StFftSphereRibbon::setup(){ gui = new ofxUICanvas(); gui->init(212, 10, 200, 200); gui->addSpacer(); gui->addLabel("STRIPE SPHERE"); gui->addSpacer(); gui->addSlider("NOISE SCALE", 0.0, 5.0, 1.0); gui->addSlider("SHIFT SPEED", 0.0, 2.0, 1.0); gui->addSlider("INTERPORATION", 0.0, 1.0, 0.2); gui->addSlider("RIBBON WIDTH", 0.0, 10.0, 4.0); gui->addSlider("ZOOM", 0.0, 3.0, 1.0); gui->addSpacer(); gui->addSlider("HUE", 0, 2.0, 1.0); gui->addSlider("SAT", 0, 2.0, 1.0); gui->addSlider("BR", 0, 2.0, 1.0); gui->addSpacer(); gui->addButton("SAVE SETTINGS", false); gui->loadSettings("StFftSphereRibbon.xml"); gui->autoSizeToFitWidgets(); gui->setVisible(false); ofAddListener(gui->newGUIEvent,this,&StFftSphereRibbon::guiEvent); app = ((ofApp*)ofGetAppPtr()); post.init(app->drawFbo->width, app->drawFbo->height); post.createPass<BloomPass>()->setEnabled(true); createMesh(); }
//------------------------------------------ void ofNotifyMouseMoved(int x, int y){ ofBaseApp * ofAppPtr = ofGetAppPtr(); static ofMouseEventArgs mouseEventArgs; if( bPreMouseNotSet ){ previousMouseX = x; previousMouseY = y; bPreMouseNotSet = false; }else{ previousMouseX = currentMouseX; previousMouseY = currentMouseY; } currentMouseX = x; currentMouseY = y; if(ofAppPtr){ ofAppPtr->mouseMoved(x,y); ofAppPtr->mouseX = x; ofAppPtr->mouseY = y; } #ifdef OF_USING_POCO mouseEventArgs.x = x; mouseEventArgs.y = y; ofNotifyEvent( ofEvents().mouseMoved, mouseEventArgs ); #endif }
void AlphaMask::draw(){ ofApp *app = ((ofApp*)ofGetAppPtr()); ofPushMatrix(); ofTranslate(960, 0); // Circle Mask (Full HD or 1980 x 630) if (app->screenMode == 0 || app->screenMode == 1) { maskCircle(); } if (app->screenMode == 2) { maskRect(); } // Rect mask in 1980 x 630 // Top & Bottom mask if (app->screenMode == 1 || app->screenMode == 2) { ofSetColor(0); ofSetRectMode(OF_RECTMODE_CORNER); ofPushMatrix(); ofRect(0, 0, 1920, 224); ofTranslate(0, 630 + 224); ofRect(0, 0, 1920, 300); ofPopMatrix(); } ofPopMatrix(); }
void StCvOpDistort::setup(){ gui = new ofxUICanvas(); gui->init(212, 10, 200, 200); gui->addSpacer(); gui->addLabel("OPTICAL PARTICLE"); gui->addSpacer(); gui->addSlider("PYR SCALE", 0, 0.99, 0.5); gui->addIntSlider("LEVELS", 1, 10, 5); gui->addIntSlider("WIN SIZE", 1, 100, 30); gui->addIntSlider("ITERATION", 1, 20, 2); gui->addToggle("GAUSS", false); gui->addSpacer(); gui->addSlider("THRESH", 0, 2.0, 1.0); gui->addIntSlider("SKIP", 1, 10, 1); gui->addSlider("TOP SHIFT", 0, 100.0, 50.0); gui->addSpacer(); gui->addSlider("HUE", 0, 2.0, 1.0); gui->addSlider("SAT", 0, 2.0, 1.0); gui->addSlider("BR", 0, 2.0, 1.0); gui->addSpacer(); gui->addButton("SAVE SETTINGS", false); gui->loadSettings("StCvOpDistort.xml"); gui->autoSizeToFitWidgets(); gui->setVisible(false); ofAddListener(gui->newGUIEvent,this,&StCvOpDistort::guiEvent); app = ((ofApp*)ofGetAppPtr()); createMesh(); }
void FFTFnwrNoise::draw(){ float br = 2.5; float pow = powf(((testApp*)ofGetAppPtr())->avg_power, 0.9) * 10.0; int skip = pow/4.0 + 2; ofRotateX(180); //ofScale(pow/100+1.2,pow/100+1.2); ofScale(1.2,1.2); ofTranslate(-fnwr.width/2, -fnwr.height/2); //ofSetRectMode(OF_RECTMODE_CENTER); ofEnableBlendMode(OF_BLENDMODE_ADD); //ofEnableBlendMode(OF_BLENDMODE_ALPHA); for (int i = 0; i < fnwr.width; i+=skip) { for (int j = 0; j < fnwr.height; j+=skip) { int r = pixels[j * fnwr.width * 3 + i * 3] * br; int g = pixels[j * fnwr.width * 3 + i * 3 + 1]* br; int b = pixels[j * fnwr.width * 3 + i * 3 + 2]* br; ofSetColor(r, 0, 0); ofRect(i, int(j - magnitude[i] * pow / 4.0), skip, skip); ofSetColor(0, g, 0); ofRect(i, j, skip, skip); ofSetColor(0, 0, b); ofRect(i, int(j + magnitude[fft_size - i] * pow / 4.0), skip, skip); } } //ofSetRectMode(OF_RECTMODE_CORNER); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofDisableLighting(); ofSetColor(120,120,120,255-pow*3); fnwr.draw(0, 0); ofEnableLighting(); ofEnableBlendMode(OF_BLENDMODE_ADD); }
void lineWithInfo::computeWidths(){ widthInfo.clear(); ofApp * appPtr = (ofApp *) ofGetAppPtr(); float minWidth = appPtr->minWidth; float maxWidth = appPtr->maxWidth; bAmILightning = appPtr->bLightningMode; float totalDistance = 0; float avgSpeed = 0; if (line.size() < 2) return; for (int i = 0; i < line.size()-1; i++){ float len = (line[i] - line[i+1]).length(); totalDistance += len; avgSpeed += len; } avgSpeed /= MAX(1.0, line.size()); float capLength = 60; float widthSmooth = minWidth; float runningDistance = 0; for (int i = 0; i < line.size(); i++){ float scalePct = 1; float scalePctForTex = 1; if (runningDistance < capLength){ scalePct = runningDistance/capLength; scalePctForTex = scalePct; } else if ( (totalDistance - runningDistance) < capLength){ scalePct = ((totalDistance - runningDistance)/capLength); scalePctForTex =scalePct * -1; } int i_p_1 = i + 1; if (i_p_1 > line.size()-1) i_p_1 = line.size()-1; float len = (line[i] - line[i_p_1 ]).length(); float widthPct = ofMap(len, 1,50, 0, 1, true);; widthSmooth = 0.85f * widthSmooth + 0.15 * ofMap(powf(widthPct, 3.4), 0, 1, minWidth, maxWidth, true); ofPoint pt; pt.x = widthSmooth * scalePct; pt.y = runningDistance; pt.z = scalePctForTex; widthInfo.push_back(pt * ofPoint(-1,1,1)); widthInfo.push_back(pt); runningDistance += len; } }
void StFftBox::setup(){ gui = new ofxUICanvas(); gui->init(212, 10, 200, 200); gui->addSpacer(); gui->addLabel("FFT Box"); gui->addSpacer(); gui->addSlider("BOX SIZE", 0, ofGetHeight(), 50.0); gui->addIntSlider("SKIP", 1, 12, 4); gui->addSlider("STIFFNESS", 0, 3.0, 1.0); gui->addRangeSlider("HUE", 0, 255, 0, 255); gui->addIntSlider("SATURATION", 0, 255, 100); gui->addIntSlider("BRIGHTNESS", 0, 127, 5); gui->addSpacer(); gui->addButton("SAVE SETTINGS", false); gui->loadSettings("StFftBox.xml"); gui->autoSizeToFitWidgets(); gui->setVisible(false); ofAddListener(gui->newGUIEvent,this,&StFftBox::guiEvent); app = ((ofApp*)ofGetAppPtr()); int fftsize = app->bufferSize; force = new float[fftsize]; size = new float[fftsize]; rotSize = new ofVec3f[fftsize]; for(int i = 0; i < fftsize; i++){ force[i] = 0.0; size[i] = 0.0; rotSize[i] = ofVec3f(ofRandom(-0.2, 0.2), ofRandom(-0.2, 0.2), ofRandom(-0.2, 0.2)); } post.init(app->drawFbo->width, app->drawFbo->height); post.createPass<BloomPass>()->setEnabled(true); }
void StCvOpSparkle::update(){ //CV params ofxUISlider *p = (ofxUISlider *)gui->getWidget("PYR SCALE"); pyrScale = p->getValue(); ofxUIIntSlider *l = (ofxUIIntSlider *)gui->getWidget("LEVELS"); levels = l->getValue(); ofxUIIntSlider *w = (ofxUIIntSlider *)gui->getWidget("WIN SIZE"); winsize = w->getValue(); ofxUIIntSlider *it = (ofxUIIntSlider *)gui->getWidget("ITERATION"); iterations = it->getValue(); ofxUIToggle *gs = (ofxUIToggle *)gui->getWidget("GAUSS"); OPTFLOW_FARNEBACK_GAUSSIAN = gs->getValue(); polyN = 7; polySigma = 1.5; ofPixelsRef pix = ((ofApp*)ofGetAppPtr())->blackmagic->colorPixels; pix.resize(160, 90); //pix.resize(40, 22); flow.setPyramidScale(pyrScale); flow.setNumLevels(levels); flow.setWindowSize(winsize); flow.setNumIterations(iterations); flow.setPolyN(polyN); flow.setPolySigma(polySigma); flow.setUseGaussian(OPTFLOW_FARNEBACK_GAUSSIAN); if (pix.size() > 0) { flow.calcOpticalFlow(pix); } for (int i = 0; i < particles.size(); i++) { particles[i]->update(); } gui->setVisible(getSharedData().guiVisible); }
//------------------------------------------ void ofNotifyMouseReleased(int x, int y, int button){ ofBaseApp * ofAppPtr = ofGetAppPtr(); static ofMouseEventArgs mouseEventArgs; if( bPreMouseNotSet ){ previousMouseX = x; previousMouseY = y; bPreMouseNotSet = false; }else{ previousMouseX = currentMouseX; previousMouseY = currentMouseY; } currentMouseX = x; currentMouseY = y; pressedMouseButtons.erase(button); if(ofAppPtr){ ofAppPtr->mouseReleased(x,y,button); ofAppPtr->mouseReleased(); ofAppPtr->mouseX = x; ofAppPtr->mouseY = y; } #ifdef OF_USING_POCO mouseEventArgs.x = x; mouseEventArgs.y = y; mouseEventArgs.button = button; ofNotifyEvent( ofEvents().mouseReleased, mouseEventArgs ); #endif }
void StCvOpMesh::draw() { ofxUIIntSlider *gmax = (ofxUIIntSlider *)gui->getWidget("MAX"); int max = gmax->getValue(); ofxUISlider *gradius = (ofxUISlider *)gui->getWidget("RADIUS"); float radius = gradius->getValue(); ofxUIIntSlider *gfade = (ofxUIIntSlider *)gui->getWidget("FADE"); int fade = gfade->getValue(); ofxUIToggle *gclear = (ofxUIToggle *)gui->getWidget("CLEAR BACKGROUND"); bool clear = gclear->getValue(); ofPixelsRef pix = ((ofApp*)ofGetAppPtr())->blackmagic->colorPixels; app->drawFbo->fbo.begin(); app->drawFbo->blendMode = 0; ofTranslate(0, -app->drawFbo->top); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofSetColor(0, 0, 0, fade); ofRect(0, 0, ofGetWidth(), ofGetHeight()); mesh.clear(); for (int i = 0; i < particles.size(); i++) { mesh.addVertex(ofVec3f(particles[i]->position.x, particles[i]->position.y, 0)); mesh.addColor(ofFloatColor(particles[i]->col.r/255.0, particles[i]->col.g/255.0, particles[i]->col.b/255.0)); } ofEnableBlendMode(OF_BLENDMODE_ADD); ofSetColor(255); glPointSize(radius); mesh.draw(); ofDisableBlendMode(); app->drawFbo->fbo.end(); gui->setVisible(getSharedData().guiVisible); }
void FFTTracer::draw(){ glEnable(GL_DEPTH_TEST); //ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofDisableLighting(); ofPushMatrix(); ofScale(1.0, 1.0, 1.0); ofRotateX(ofGetElapsedTimef() * 4); ofRotateY(ofGetElapsedTimef() * 3); ofRotateZ(ofGetElapsedTimef() * 2); for (int i=0; i<fft_size; i++) { if(magnitude[i] > 1){ ofSetColor(ofColor::fromHsb(255 * i / fft_size, 200, 120)); float w = powf(((testApp*)ofGetAppPtr())->power[i],4.0); if (w > 10) { w = 10; } ofSetLineWidth(w); trackers[i]->draw(); } } ofPopMatrix(); ofEnableLighting(); glDisable(GL_DEPTH_TEST); //ofEnableBlendMode(OF_BLENDMODE_ADD); }