//-------------------------------------------------------------- void App::setup(){ // Disable the of setupScreen because now each scene has a custom renderer. ofDisableSetupScreen(); //Create a scene. //The scene is a scene graph that renders objects added to its root and their children and their children's children and so on. //When the render mode of the scene is set to RENDER_ALPHA_DEPTH_SORTED, it handles sorting of both transparent and opaque objects in the z-axis. scene = new ofxScene(ofGetWidth(), ofGetHeight()); scene->setBackgroundColor(defaultR, defaultG, defaultB); //Create Circle Object circle = new ofxCircleObject(defaultRes, 50); circle->setTrans(xPosition, yPosition, 0); circle->setScale(sliderScale/100); scene->getRoot()->addChild(circle); //Smile eye1 = new ofxCircleObject(30, 6); eye2 = new ofxCircleObject(30, 6); arcSmile = new ofxArcObject(28,26, 200, 340); eye1->setColor(255, 255, 255, 0); eye1->setTrans(-15, 15, 1); eye2->setColor(255, 255, 255, 0); eye2->setTrans(15, 15, 1); arcSmile->setColor(255, 255, 255, 0); arcSmile->setTrans(0, 0, 1); circle->addChild(eye1); circle->addChild(eye2); circle->addChild(arcSmile); // Build UIObject UIObject = new exampleUIObject(); UIObject->setup(); scene->getRoot()->addChild(UIObject); UIObject->setVisible(true); int cornerOffset = 20; int UI_x = -ofGetWindowWidth()/2 + cornerOffset; int UI_y = ofGetWindowHeight()/2 - cornerOffset; UIObject->setTrans(UI_x, UI_y, 0); // Add Event Listeners ofAddListener(UIObject->UI->newGUIEvent, this, &App::UIEvent); }
//-------------------------------------------------------------- void testApp::draw(){ if(calibrating){ ofSetColor(255); ofDrawBitmapString("calibrating", 100,100); } else { ofSetColor(0,0,0, 2); ofRect( 0,0, ofGetWindowWidth(), ofGetWindowHeight() ); drawLines(); } syphon.publishScreen(); ofSetColor(255); string thisMsg = ofToString(sensorMax[0]); ofDrawBitmapString("sensorMax 1: "+thisMsg, 300, 50); thisMsg = ofToString(sensorMin[0]); ofDrawBitmapString("sensorMin 1: "+thisMsg, 300, 75); thisMsg = ofToString(amplitude[0]); ofDrawBitmapString("amplitude 1: "+thisMsg, 300, 100); thisMsg = ofToString(breath[0]); ofDrawBitmapString("breath 1: "+thisMsg, 300, 125); thisMsg = ofToString(sensorMax[1]); ofDrawBitmapString("sensorMax 2: "+thisMsg, 600, 50); thisMsg = ofToString(sensorMin[1]); ofDrawBitmapString("sensorMin 2: "+thisMsg, 600, 75); thisMsg = ofToString(amplitude[1]); ofDrawBitmapString("amplitude 2: "+thisMsg, 600, 100); thisMsg = ofToString(breath[1]); ofDrawBitmapString("breath 2: "+thisMsg, 600, 125); thisMsg = ofToString(sensorMax[2]); ofDrawBitmapString("sensorMax 3: "+thisMsg, 900, 50); thisMsg = ofToString(sensorMin[2]); ofDrawBitmapString("sensorMin 3: "+thisMsg, 900, 75); thisMsg = ofToString(amplitude[2]); ofDrawBitmapString("amplitude 3: "+thisMsg, 900, 100); thisMsg = ofToString(breath[2]); ofDrawBitmapString("breath 3: "+thisMsg, 900, 125); }
void Background::draw() { this->cpt += 0.4; this->shader.begin(); this->shader.setUniform1f("cpt", this->cpt); this->shader.setUniform1f("noiseInfluence", this->noiseInfluence); // de 0 à 1 this->shader.setUniform1f("noiseScale", this->noiseScale); this->shader.setUniform1f("alpha", this->alpha); this->shader.setUniformTexture("tex", this->image[this->currentImage].getTextureReference(), 0); this->shader.setUniform2f("resolution", ofGetWindowWidth(), ofGetWindowHeight()); this->screen.draw(); this->shader.end(); //this->fbo.draw(0, 0); }
void Particle::update( float dt ){ vel += accel; pos += (vel * dt * 50); if( pos.x < 0 || pos.x > ofGetWindowWidth() ){ vel.x *= -1; } if( pos.y < 0 || pos.y > ofGetWindowHeight() ){ vel.y *= -1; } // vel*= 0.97; accel.set(0); }
//-------------------------------------------------------------- void testApp::draw(){ //changeBackgroundColor(); ofPushStyle(); ofFill(); ofSetColor(0,0,0, fadeAmnt); ofRect(0,0,ofGetWindowWidth(),ofGetWindowHeight()); ofPopStyle(); //draw our fbo with some cute shaders on top xoxo bloomShader.begin(); bloomShader.setUniformTexture("texture", rgbaFboFloat.getTextureReference(), 1); rgbaFboFloat.draw(0,0); bloomShader.end(); }
//-------------------------------------------------------------- void testApp::draw(){ ofSetRectMode(OF_RECTMODE_CORNER); ofSetColor(0, 25); ofRect(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); for ( vector<Particle>::iterator it=particles.begin(); it!=particles.end(); ) { it->draw(); it++; } for (int i=0; i<80; i++) { addParticle(pos, setVel, hue); } }
//-------------------------------------------------------------- void testApp::draw(){ if ( gameState == 0 ) { ofSetRectMode(OF_RECTMODE_CORNER); startScreen.draw(0,0, ofGetWindowWidth(), ofGetWindowHeight()); return; } //secondBackground.draw(); // Matt //cout<<bulletList.size()<<endl; {//Mauricio // enemyFbo.begin(); // ofSetColor(255, 255, 255); // ofClear(255, 255, 255, 0); { // Matt //cam.begin(); // //cam.setupPerspective(); /*if ( killFrameRate ) */drawGalaxy(); //Mauricio: For some reason the only way that our metroid animation works is by passing the frameNum from the testApp. I initally had everything inside the class but it didn't work. Passing the frameNum throught the draw it works. if ( !metroid.bDestroyMe ) metroid.draw(frameNum); } // enemyFbo.end(); // enemyFbo.draw( ofGetWindowWidth() , ofGetWindowHeight()); } { // Mauricio //ship1.draw(); } { // Matt for ( int i = 0; i < shipList.size(); i++ ) { shipList[ i ].draw(); } for ( int i = 0; i < bulletList.size(); i++ ) { bulletList[ i ].draw(); } //cam.end(); } }
//-------------------------------------------------------------- void testApp::setup(){ looping = false; started = false; fullscreen = false; count = 0; // Load initial settings loadSettings("settings.xml"); ofSetVerticalSync(true); // open an outgoing connection to HOST:PORT sender1.setup( host1, port1 ); sender2.setup( host2, port2 ); // Load movie file movie.loadMovie(movieFile); movie.play(); // Turns looping off if (!looping) { movie.setLoopState(OF_LOOP_NONE); } else { movie.setLoopState(OF_LOOP_NORMAL); } ofBackground( 0, 0, 0 ); mp3.loadSound("../../../../../../../music/feeling.mp3"); fftSmoothed = new float[8192]; for (int i = 0; i < 8192; i++){ fftSmoothed[i] = 0; } nBandsToGet = movie.getHeight(); movie.setVolume(0); mp3.play(); yStep = 10; xStep = 10; fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA32F_ARB); drawRuttEtra = true; }
//-------------------------------------------------------------- void ofApp::setup(){ // // ofSetFrameRate(60); // float x = ofGetWindowWidth()/2; float y = ofGetWindowHeight()/2; pos.set(x,y); numCircles = 25; for (int i = 0; i < numCircles; i++){ circle myCircle; circles.push_back(myCircle); } }
/* Constructor */ Particle::Particle(){ size = ofRandom(20); color.set(255, 0, 50); strokeColor.set(0, 0, 0); pos.set( ofGetWindowWidth()*0.5, ofGetWindowHeight()*0.5 ); vel.set( ofRandom(-1,1), ofRandom(-1,1)); acc.set( 0, 0 ); alphaF = 1; scaleF = 1; damp = 0.05; life = initialLife = ofRandom( 200, 1000 ); }
//-------------------------------------------------------------- void testApp::setup(){ //Allows clear updating of vertically on the screen ofSetVerticalSync(true); ofSetRectMode(OF_RECTMODE_CENTER); myRect.pos.x = ofRandom(0, ofGetWindowWidth()); myRect.pos.y = ofRandom(0, ofGetWindowHeight()); }
//-------------------------------------------------------------- void ofApp::draw(){ int width = ofGetWindowWidth(); int height = ofGetWindowHeight(); int w = width/MAX_SIZE; for(int i = 0; i < MAX_SIZE; i++) { ofSetColor(144,144,144); ofFill(); ofRect(i*w, height - randomCounts[i], w, randomCounts[i]); ofSetColor(44,44,44); ofNoFill(); ofRect(i*w, height - randomCounts[i], w, randomCounts[i]); } }
void videoApp::draw() { // LOGO --------------------------------- logoWidth = ofGetWindowWidth()/2; logoHeight = logoWidth * logo.height / logo.width; logo.draw(ofGetWindowWidth()/2-logoWidth/2, ofGetWindowHeight()/2-logoHeight/2, logoWidth, logoHeight); // SERIAL ------------------------------- byte = serial.readByte(); if ( byte == OF_SERIAL_NO_DATA ) cout << "no data was read" << endl; else if ( byte == OF_SERIAL_ERROR ) cout << "an error occurred" << endl; else cout << "myByte is " << byte << endl; if(byte == 10 && !salsa.isPlaying()) { jive.stop(); waltz.stop(); salsa.play(); } if(byte == 11 && !jive.isPlaying()) { salsa.stop(); waltz.stop(); jive.play(); } if(byte == 12 && !waltz.isPlaying()) { salsa.stop(); jive.stop(); waltz.play(); } if(byte == 255) { salsa.stop(); jive.stop(); waltz.stop(); } if(salsa.isPlaying()) salsa.draw(0, 0, movieWidth, movieHeight); if(jive.isPlaying()) jive.draw( 0, 0, movieWidth, movieHeight); if(waltz.isPlaying()) waltz.draw(0, 0, movieWidth, movieHeight); }
void Coin::move() { posX += velX; posY += velY; posZ += velZ; float time = ofGetElapsedTimef(); //Get time in seconds //rotate at [rotation angle] per second rotX = time * rotAngX; rotY = time * rotAngY; rotZ = time * rotAngZ; if (posY > (ofGetWindowHeight() + radius)){ setup(); } }
Ball::Ball(){ //set the initial color color.set(ofRandom(255), ofRandom(255), ofRandom(255)); //counter TODO: make this exist in the main app counter = 0.0; speed = 0.008; radius = ofGetWindowWidth()/4; //initial x position of the ball - center x = ofGetWindowWidth()/2; //initial y position of the ball - center y = ofGetWindowHeight()/2; }
// fonction qui exporte une image à partir de son nom et de son extension, à partir du répertoire ./bin/data ou d'un chemin absolue void Renderer::imageExport(const string name, const string extension) const { ofImage imageTemp; // extraire des données temporelles formatées string timestamp = ofGetTimestampString("-%y%m%d-%H%M%S-%i"); // générer un nom de fichier unique et ordonné string fileName = name + timestamp + "." + extension; // capturer le contenu du framebuffer actif imageTemp.grabScreen(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); // sauvegarder le fichier image imageTemp.save(fileName); ofLog() << "<export image: " << fileName << ">"; }
void WinScreen::draw(){ background(); ofSetColor(250, 200); font.drawString("Congratulations you beat all the levels", ofGetWidth()*0.2, ofGetHeight()*0.3); font.drawString("Total Score: "+ ofToString(getscore()) , ofGetWidth()*0.4, ofGetWindowHeight()*0.5); if(button(0.5,0.8, "Main Menu")) { State::setState(MM);//sends you to the next gamestate //State::gameStates[LVL1].get()->resetLevel(); } }
//-------------------------------------------------------------- EVENTS void ofxComposer::_keyPressed(ofKeyEventArgs &e){ if (e.key == OF_KEY_F1 ){ bHelp = !bHelp; } else if (e.key == OF_KEY_F2 ){ bEditMode = !bEditMode; } else if ((e.key == OF_KEY_F3 ) || (e.key == OF_KEY_F4 ) ){ // Special keys reserved for Patch Events // } else if (e.key == OF_KEY_F5 ){ if ( bGLEditorPatch ) addPatchWithOutFile("ofVideoGrabber", ofPoint(ofGetMouseX(),ofGetMouseY())); else bGLEditorPatch = addPatchWithOutFile("ofxGLEditor", ofPoint(ofGetMouseX(),ofGetMouseY())); } else if ( e.key == OF_KEY_F6 ){ addPatchWithOutFile("ofShader", ofPoint(ofGetMouseX(),ofGetMouseY())); } else if (e.key == OF_KEY_F7){ ofToggleFullscreen(); #ifdef USE_OFXGLEDITOR editor.reShape(); editorFbo.allocate(ofGetWindowWidth(),ofGetWindowHeight()); editorFbo.begin(); ofClear(editorBgColor); editorFbo.end(); #endif } else { // If no special key was pressed and the GLEditor is present pass the key // #ifdef USE_OFXGLEDITOR editor.keyPressed(e.key); if (selectedID >= 0){ if (patches[selectedID]->getType() == "ofShader"){ patches[selectedID]->setFrag(editor.getText(1)); patches[selectedID]->saveSettings(); } } #endif } }
void Particles::update(ofImage img){ //Uncomment if you want to have some particles dancing. It might get super slow though. // pos.x = ofRandom(0, ofGetWindowWidth()); // pos.y = ofRandom(0, ofGetWindowHeight()); diagonal = ofDist( 0, 0 , ofGetWindowWidth(), ofGetWindowHeight()); tempSize = ofDist(ofGetMouseX(), ofGetMouseY(), pos.x, pos.y); rectSize = ofMap( tempSize, 0, diagonal, 0, rectSizeMax); pixelColor = img.getColor(pos.x,pos.y); }
void textInput::drawRects() { ofSetLineWidth(1.0f); int width = ofGetWindowWidth() - 20; int height = 40; cursory= ofGetWindowHeight() - (height+10); ofSetColor(255); ofRect(cursorx+1,cursory,width-1,height-1); ofSetColor(0); // NW to SW ofLine(cursorx, cursory-1, cursorx, cursory+height); ofLine(cursorx, cursory, cursorx+width, cursory); ofLine(cursorx+width, cursory, cursorx+width, cursory+height); ofLine(cursorx, cursory+height, cursorx+width, cursory+height); font.drawWString(text, startx+10, cursory+33); }
void ofCairoRenderer::viewport(float x, float y, float width, float height, bool invertY){ if(width == 0) width = ofGetWindowWidth(); if(height == 0) height = ofGetWindowHeight(); if (invertY){ y = -y; } viewportRect.set(x, y, width, height); cairo_reset_clip(cr); cairo_new_path(cr); cairo_move_to(cr,viewportRect.x,viewportRect.y); cairo_line_to(cr,viewportRect.x+viewportRect.width,viewportRect.y); cairo_line_to(cr,viewportRect.x+viewportRect.width,viewportRect.y+viewportRect.height); cairo_line_to(cr,viewportRect.x,viewportRect.y+viewportRect.height); cairo_clip(cr); };
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(30, 30, 30); ofSetVerticalSync(true); ofSetFrameRate(60); ofEnableAlphaBlending(); //one particle //mParticle=Particle(200.0f,200.0f,30.0f); //more for(unsigned int i=0;i<amount;i++){ float x = ofRandom(ofGetWindowWidth()); float y = ofRandom(ofGetWindowHeight()); float r=ofRandom(10.0f,20.0f); float xspeed = (int)ofRandom(2,5); float yspeed = (int)ofRandom(2,5); mPCluster.push_back(Particle(x,y,r,xspeed,yspeed)); } }
//-------------------------------------------------------------- void testApp::update(){ pos.x=ofRandom(ofGetWindowWidth()); pos.y=ofRandom(ofGetWindowHeight()-100); setVel=ofRandom(5,7.5); hue=ofRandom(255); for ( vector<Particle>::iterator it = particles.begin(); it!=particles.end(); ) { it->update(); if ( it->kill() ) { it = particles.erase(it); } else { it++; } } }
//-------------------------------------------------------------- void testApp::draw() { ofSetColor(64); ofRect(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); ofEnableAlphaBlending(); ofSetColor(255); for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { NamekoImages::iterator it = nameko.find(state[x][y].id); if (it != nameko.end()) { it->second->draw(x * 50, y * 50); } } } for (Answers::iterator it = answers.begin(); it != answers.end(); ++it) { if (it->x1 == it->x2) { verticalFrame.draw(it->x1 * 50, it->y1 * 50); } else { horizontalFrame.draw(it->x1 * 50, it->y1 * 50); } } // for (int y = 0; y < 8; y++) { // for (int x = 0; x < 8; x++) { // ofSetColor(0); // ofRect(x * 50, y * 50, 16, 16); // ofSetColor(255); // ofDrawBitmapString(ofToString(state[x][y].count), x * 50, y * 50 + 16); // } // } // ofSetColor(0, 0, 0, 128); // ofRect(0, 0, 100, 200); // ofSetColor(255); // int y = 16; // for (map<unsigned int, int>::iterator it = count.begin(); it != count.end(); it++) { // ofDrawBitmapString(ofToString(it->first) + ": " + ofToString(it->second), 0, y); // y += 20; // } }
void Coin::setup() { //this function sets up a coin with random: //radius, posX, posZ, //silver or gold color, //spin speed/direction radius = ofRandom(40,70); posX = ofRandom(radius,(ofGetWindowWidth()-radius)); //between the window edges posY = (0 - (ofRandom(radius, (ofGetWindowHeight()*2)))); //start above top of screen posZ = ofRandom(-125,125); //250 depth // angle of rotation from 2 to 20 rotAngX = ofRandom(2, 90); rotAngY = ofRandom(2, 90); rotAngZ = ofRandom(2, 90); rotX = 0; rotY = 0; rotZ = 0; velX = 0; //no move along X velY = 4; //speed of gravity velZ = 0; //no move along Z //set color to silver or gold float colSelect = ofRandom(0,1); if (colSelect >= 0.5){ //silver (grey) r = 182; g = 182; b = 182; } else { //gold(-ish) r = 218; g = 183; b = 74; } }
//-------------------------------------------------------------- void testApp::draw(){ // Why not do this? What's the benefit of vector subtraction? // ofLine( ofPoint(mouseX,mouseY), ofPoint(ofGetWindowWidth()/2, ofGetWindowHeight()/2) ); ofPushMatrix();{ ofTranslate( ofGetWindowSize() / 2 ); ofVec2f mousePos( mouseX, mouseY ); ofVec2f center( ofGetWindowWidth()/2, ofGetWindowHeight()/2 ); mousePos = mousePos - center; ofLine( ofPoint(0,0), mousePos ); }ofPopMatrix(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofBackground(200); ofPushMatrix(); ofPushStyle(); ofTranslate(ofGetWindowWidth() / 2, ofGetWindowHeight() / 2); ofSetCircleResolution(32); float diff = ofGetElapsedTimef() - floor(ofGetElapsedTimef()); for( int i = 16; i > 0; i-- ) { ofFill(); ofSetColor(ofMap(i, 0, 16, 50, 200)); ofCircle(0, 0, ofMap(i - diff, 0, 16, 0, ofGetWindowWidth() / 2)); } ofPopStyle(); ofPopMatrix(); spidar.draw(0xfefefe); }
void fftHandler::plotColorRect(float* array, int length, float x, float y, float width, float height) { int cropfactor = 8; int crop = fft->getBinSize()/cropfactor; float pwidth = width / (float)crop; ofPushMatrix(); ofPushStyle(); for (int i = 0 ; i < crop; i++) { float ratio = 400.0f / (float)crop; // ofColor colorise; // colorise.setHsb((i*ratio), min(array[i]*2555.0f,255.0f), min(array[i]*2555.0f,255.0f)); ofFill(); ofColor fillColor = getColorInSpec(((int)(i*ratio)+380)); fillColor.setBrightness( max( min( array[i]*2550.0f*intensity, 255.0f ), 10.0f ) ); ofSetColor( fillColor ); ofRect(pwidth*i,0,pwidth,ofGetWindowHeight()); } ofPopStyle(); ofPopMatrix(); }
//-------------------------------------------------------------- void testApp::update(){ ballPos+=vel; if (ballPos.x < 0 || ballPos.x > ofGetWindowWidth() * 4 ) { vel.x*=-1; } if (ballPos.y < 0 || ballPos.y > ofGetWindowHeight() ) { vel.y*=-1; } ofxOscMessage m2; m2.setAddress("/ball/pos"); m2.addIntArg(ballPos.x); m2.addIntArg(ballPos.y); mSender.sendMessage( m2 ); }
void GBuffer::drawDebug(int x, int y) { int wy = ofGetWindowHeight() - y - 256; glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo); glReadBuffer(GL_COLOR_ATTACHMENT0); glBlitFramebuffer(0, 0, m_fbo_w, m_fbo_h, 0+x, 0+wy, 256+x, 256+wy, GL_COLOR_BUFFER_BIT, GL_LINEAR); glReadBuffer(GL_COLOR_ATTACHMENT1); glBlitFramebuffer(0, 0, m_fbo_w, m_fbo_h, 256+x, 0+wy, 512+x, 256+wy, GL_COLOR_BUFFER_BIT, GL_LINEAR); glReadBuffer(GL_COLOR_ATTACHMENT2); glBlitFramebuffer(0, 0, m_fbo_w, m_fbo_h, 512+x, 0+wy, 768+x, 256+wy, GL_COLOR_BUFFER_BIT, GL_LINEAR); glReadBuffer(GL_COLOR_ATTACHMENT3); glBlitFramebuffer(0, 0, m_fbo_w, m_fbo_h, 768+x, 0+wy, 1024+x, 256+wy, GL_COLOR_BUFFER_BIT, GL_LINEAR); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); }