//-------------------------------------------------------------- void testApp::mouseMoved(int x, int y){ ofVec2f eventPos = ofVec2f(x, y); ofVec2f mouseNorm = ofVec2f(eventPos) / ofGetWindowSize(); ofVec2f mouseVel = ofVec2f(eventPos - pMouse) / ofGetWindowSize(); addToFluid(mouseNorm, mouseVel, true, true); pMouse = eventPos; }
void testApp::mouseDragged(int x, int y, int button) { ofVec2f eventPos = ofVec2f(x, y); ofVec2f mouseNorm = ofVec2f(eventPos) / ofGetWindowSize(); ofVec2f mouseVel = ofVec2f(eventPos - pMouse) / ofGetWindowSize(); addToFluid(mouseNorm, mouseVel, false, true); pMouse = eventPos; }
void SunParticle::update() { vel *= damping; pos = pos + vel; lifeSpan++; if(lifeSpan > ageOfDeath){ //reset life counter lifeSpan = 0;; //then give a new random position float phi = ofRandom( 0, TWO_PI ); float costheta = ofRandom( -1.0f, 1.0f ); float rho = sqrt( 1.0f - costheta * costheta ); float x = rho * cos( phi ); float y = rho * sin( phi ); float z = costheta; ofVec3f randVec(x, y, z); pos = randVec * ofRandom( 80.0f, 250.0f ); pos.x = pos.x + ofGetWindowWidth()/2; pos.y = pos.y + ofGetWindowHeight()/2; ofVec3f toCenter = pos - ofVec3f(ofGetWindowSize()/2); toCenter.normalize(); vel = toCenter * ofRandom(0.5, 2); if(explode){ pos = ofVec3f(ofGetWindowSize()/2); vel = ofVec3f(ofRandom(-20, 20), ofRandom(-20, 20), ofRandom(0, 20)); } if(size < 80){ size += 5; } else { size = 0; } } // resetForces(); }
//-------------------------------------------------------------- void testApp::setup(){ pos = ofGetWindowSize() / 2; pos_2 = ofGetWindowSize() / 2; // vel.set( 20, 10, 0 ); vel.set( 5, 7, 0 ); vel_2.set( -3, 10, 0 ); mFbo.allocate( ofGetWindowWidth(), ofGetWindowHeight() ); mFbo2.allocate( ofGetWindowWidth(), ofGetWindowHeight() ); ofBackground(0); ofEnableAlphaBlending(); }
void ofApplication::drawTouches() { int touchCount = touchMap.size(); if (touchCount > 0){ touchLine.clear(); if (touchCount <= 3){ if (touchCount == 1){ ofVec2f point = (*touchMap.begin()).second; ofCircle(point, 2.0f); } else{ map<int,ofVec2f>::iterator it = touchMap.begin(); while (it != touchMap.end()){ touchLine.addVertex((*it++).second*ofGetWindowSize()); } if (touchCount == 3) touchLine.close(); } } ofSetLineWidth(3.0f); ofSetColor(ofFloatColor(1.0f - bgBrightnessFade)); touchLine.draw(); } }
//-------------------------------------------------------------- void testApp::draw(){ // Gl frame clear so we can capture it with syphon glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //----------------draw to shyphon here--------------- //let's draw a circle: ofSetColor(255,130,0); float radius = 50 + 10 * sin(counter); ofFill(); // draw "filled shapes" ofCircle(ofGetWindowSize()/2,radius); mainOutput.publishScreen(); // push the frame to the server //----------------draw outside shyphon here--------------- //debug stuff ofDrawBitmapString("hello debug view", 10,10); }
void testApp::perlinBlob(int base, float range, int randSeed, int rot){ float speed = 0.2; float fringeWidth = base * range; ofPushMatrix();{ ofTranslate( ofGetWindowSize() / 2); ofRotate(rot); ofBeginShape(); for (int i = 0; i < 100; i++){ //Code borrowed from Charley Whitney (Algorithmic Animations Fall 2013) float add = ofNoise(i/20.0f, ofGetElapsedTimef() * speed + randSeed); //this will draw a circle with a min radius of the incoming value //plus the fringe value ofVertex( (base - fringeWidth * add) * cos((i/100.0)*TWO_PI), (base - fringeWidth * add) * sin((i/100.0)*TWO_PI)); } //ofVertex(firstX, firstY); ofEndShape(); }ofPopMatrix(); }
//-------------------------------------------------------------- void testApp::draw(){ ofDrawBitmapString("Fort Knox", 500, 580); ofBackgroundGradient(ofColor(200, 25), ofColor(237*(fftSmoothed[0]), 20, 90, 25), OF_GRADIENT_CIRCULAR); ofTranslate(ofGetWindowSize()/2); ofSetColor(0); ofNoFill(); ofPushMatrix();{ ofBeginShape();{ ofRotate(degrees); for (int i = 0; i < points; i++){ ofVertex(pos[i]); //string posStr = ofToString(i)+":"+ofToString(pos[i].x)+","+ofToString(pos[i].y); //ofDrawBitmapString(posStr, pos[i]-10); } ofVertex(pos[0]); // close the shape }ofEndShape(); }ofPopMatrix(); ofFill(); for(int i = 0; i < points; i++){ //ofCircle(pos[i].x, pos[i].y, 4); } }
void testApp::draw(){ if(drawFluid) { ofClear(0); glColor3f(1, 1, 1); fluidDrawer.draw(0, 0, ofGetWidth(), ofGetHeight()); } else { // if(ofGetFrameNum()%5==0) fadeToColor(0, 0, 0, 0.1); } if(drawParticles) particleSystem.updateAndDraw(fluidSolver, ofGetWindowSize(), drawFluid); outputSyphonServer.publishScreen(); // ofDrawBitmapString(sz, 50, 50); #ifdef USE_GUI gui.draw(); #endif myVideo->draw(); if(DrawOSCMessage){ string buf; buf = "Listening for osc messages on port: " + ofToString(PORT); ofDrawBitmapString(buf, 450, 150); for (int i=0; i< NUM_MSG_STRINGS; i++) { ofDrawBitmapString(msg_strings[i],450, 150+15+15*i); } } stringstream titleStream; titleStream<<"x, y factors: "<<xFactor<<" : "<<yFactor; ofSetWindowTitle(titleStream.str()); }
//-------------------------------------------------------------- void testApp::update(){ // This is how you loop through and delete a particle using iterators and vectors // Note how we don't put it++ up in the top of the loop. for( vector<Particle>::iterator it=pList.begin(); it!=pList.end(); ){ it->update(); if( it->bIsDead ){ it = pList.erase(it); // When we erase one, it returns the next particle automatically. It's done the "it++" for us! ofLog( OF_LOG_NOTICE, "size is " + ofToString(pList.size()) ); }else { it++; } // When the current batch of fireworks runs out, spawn a new batch at the location of the last firework. if (pList.size() <= 1) { for( int i=0; i<50; i++ ){ if (it->pos.x > 0 && it->pos.x < ofGetWindowWidth() && it->pos.y > 0 && it->pos.y < ofGetWindowHeight()) { addParticle(it->pos); }else { addParticle(ofGetWindowSize()/2); // If the pos is offscreen, relocate to the center of the screen. } } } } }
// add force and dye to fluid, and create particles void FluidVisualization::addToFluid(ofVec2f pos, ofVec2f vel, bool addColor, bool addForce) { float speed = vel.x * vel.x + vel.y * vel.y * msa::getWindowAspectRatio() * msa::getWindowAspectRatio(); // balance the x and y components of speed with the screen aspect ratio if(speed > 0) { pos.x = ofClamp(pos.x, 0.0f, 1.0f); pos.y = ofClamp(pos.y, 0.0f, 1.0f); int index = fluidSolver.getIndexForPos(pos); if(addColor) { // Color drawColor(CM_HSV, (getElapsedFrames() % 360) / 360.0f, 1, 1); ofColor drawColor; //drawColor.setHsb((ofGetFrameNum() % 255), 255, 255); drawColor.setHsb(colorH, colorS, colorB); fluidSolver.addColorAtIndex(index, drawColor * colorMult); if(drawParticles) particleSystem.addParticles(pos * ofVec2f(ofGetWindowSize()), 10); } if(addForce) fluidSolver.addForceAtIndex(index, vel * velocityMult); } }
//-------------------------------------------------------------- void SuperGraphics::draw(){ ofSetColor(255,255,255); ofBackground(255,255,255); //background.draw(0,0, ofGetWindowWidth(), ofGetWindowHeight()); ofSetColor(255, 255, 255); videoPlayer.draw(0,0, ofGetWindowWidth(), ofGetWindowHeight()); camera.begin(); ofTranslate(ofGetWindowSize()/2); ofScale(scale, scale); ofRotateY(rotation); ofTranslate(-graphic.getSize()/2); for(int i=0; i<particles.size(); i++) { ofPushMatrix(); //ofTranslate(0,0,cos((ofGetFrameNum()+i*5)/50.) * 100); particles[i].draw(); ofPopMatrix(); } camera.end(); ofSetColor(255, 255, 255, scale * 128); videoPlayer.draw(0,0, ofGetWindowWidth(), ofGetWindowHeight()); }
/* ** plot ** Plots the data in the buffer */ void ofxScopePlot::plot() { //float xPlotScale = ofGetWindowSize().x / _pointsPerWin * ofGetWindowSize().x / (_max.x - _min.x); float xPlotScale = (_max.x - _min.x) / (_pointsPerWin - 1);// * (_max.x - _min.x) / ofGetWindowSize().x; float yPlotScale = (_max.y - _min.y) / ofGetWindowSize().y; float yPlotOffset = ((_max.y - _min.y) / 2.); //printf("xPlotScale: %f, yPlotScale: %f, yPlotOffset: %f\n", xPlotScale, yPlotScale, yPlotOffset); //ofScale(1., 1., 1.); // Background ofEnableAlphaBlending(); ofSetColor(_backgroundColor); ofRect(ofRectangle(_min, _max)); // Scope zero line ofSetColor(_zeroLineColor); ofLine(_min.x, _min.y + (_max.y - _min.y)/2, _max.x, _min.y + (_max.y - _min.y)/2); ofDisableAlphaBlending(); for (int i=0; i<getNumVariables(); i++) { ofSetColor(_variableColors.at(i)); ofSetLineWidth(_plotLineWidth); for (int j=1; j<_pointsPerWin; j++) { ofPoint p1 = ofPoint(_max.x-((float)(j-1)*xPlotScale), _max.y-(yPlotScale*((_buffer.at(i).at(j-1) * _yScale + _yOffset)) + yPlotOffset)); ofPoint p2 = ofPoint(_max.x-((float)(j)*xPlotScale), _max.y-(yPlotScale*((_buffer.at(i).at(j) * _yScale + _yOffset)) + yPlotOffset)); ofLine(p1, p2); //printf("[%i, %i]: ofLine([%.1f, %.1f], [%.1f, %.1f]): buffer[%.1f],[%.1f]\n", i, j, p1.x, p1.y, p2.x, p2.y, _buffer[i][j-1], _buffer[i][j]); //ofLine(_max.x-(float)(j-1), (_buffer[i][j-1] * _yScale) + yPlotOffset, _max.x-(float)j, (_buffer[i][j] * _yScale) + yPlotOffset); //printf("[%i, %i]: ofLine(%f, %f, %f, %f)\n", i, j, _max.x-(float)(j-1), (_buffer[i][j-1] * _yScale) + yPlotOffset, _max.x-(float)j, (_buffer[i][j] * _yScale) + yPlotOffset); } } }
//-------------------------------------------------------------- void testApp::draw(){ // ofSetColor( circleColor ); // ofCircle( ofGetWindowSize()/2, circleRadius ); ofSetColor(blobColor); ofPushMatrix();{ ofTranslate( ofGetWindowSize() / 2); ofBeginShape(); noisePar = 20.0f; for (int i = 0; i < 100; i++){ float add = ofNoise(i/noisePar, ofGetElapsedTimef() * 3 * (float)ofGetHeight() / (float)ofGetWidth()); // this will draw a circle with a min radius of 200, and a max of 300 ofVertex( (circleRadius + outerRadius * add) * cos((i/100.0)*TWO_PI), (circleRadius + outerRadius * add) * sin((i/100.0)*TWO_PI)); } ofEndShape(); }ofPopMatrix(); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetCircleResolution(50); ofSetWindowTitle("openframeworks gvf visualiser"); ofSetWindowShape(1024, 768); ofSetFrameRate(60); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps. ofPoint wSize = ofGetWindowSize(); scrW = wSize.x; scrH = wSize.y; printf("w: %d h: %d\n", scrW, scrH); drawArea = ofRectangle(ofPoint(0, 0), ofGetWindowWidth(), ofGetWindowHeight()); currentGesture.setDrawArea(drawArea); isMouseDrawing = false; viewYRotation = 0; viewXRotation = 0; initializeGui(); initColors(); //leap: open the controller leap.open(); }
//-------------------------------------------------------------- void testApp::draw(){ ofPushMatrix(); ofTranslate(ofGetWindowSize()/2); myCircle.drawCircle(0,0,250); ofPopMatrix(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofVec2f center = ofGetWindowSize()/2; float y = center.y + (sine * radius); float x = center.x + (cosine * radius); ofSetColor(255); ofCircle(center, 5); ofCircle(x, y, 15); stringstream debug; debug << "Degrees: " << degrees << endl << "PI Radians: " << ofDegToRad(degrees) / PI << endl << "Sine: " << sine << endl << "Cosine: " << cosine << endl; ofSetColor(255, 0, 0); ofDrawBitmapString(debug.str(), x + 25, y); ofLine(ofGetWidth()/2, 0, ofGetWidth()/2, ofGetHeight()); ofLine(0, ofGetHeight()/2, ofGetWidth(), ofGetHeight()/2); ofLine(x, y, x, center.y); ofLine(x, y, center.x, y); ofLine(center.x, center.y, x, y); }
//-------------------------------------------------------------- void testApp::setup(){ ofSeedRandom(); dest1 = ofVec2f( ofRandomWidth(), ofRandomHeight() ); dest2 = ofVec2f( ofRandomWidth(), ofRandomHeight() ); car1.setParams( ofGetWindowSize() / 2, ofVec2f(10, -5) ); car2.setParams( ofGetWindowSize() / 2, ofVec2f(10, 5) ); car1.color = ofColor(0,255,0); car2.color = ofColor(0,0,255); ofBackground(255); ofEnableAlphaBlending(); }
void ParticleSystem::setColorMode(int colorMode) { for(int i=0; i<MAX_PARTICLES; i++) { particles[i].setColorMode(colorMode); particles[i].updateVertexArrayColors(false, ofGetWindowSize(), i, posArray, colArray); } }
void testApp::touchMoved(ofTouchEventArgs &touch) { // e.g. // touches are normalized ofVec2f pos(touch.x, touch.y); // now scaled for screen coords pos *= ofGetWindowSize(); printf("pos: %f %f\n", pos.x, pos.y); }
//-------------------------------------------------------------- void testApp::draw(){ ofBackground(0); ofPushMatrix(); ofTranslate(ofGetWindowSize()/2); for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 25), ofRandom(0, 60), ofRandom(0, 105)); ofCircle( (ofSignedNoise(i*0.1+x)*100) -400, ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 55), ofRandom(0, 55), ofRandom(0, 55)); ofCircle( (ofSignedNoise(i*0.1+x)*100) -300, ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 100), ofRandom(0, 90), ofRandom(0, 155)); ofCircle( (ofSignedNoise(i*0.1+x)*100) -200, ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 15), ofRandom(0, 15), ofRandom(0, 155)); ofCircle( (ofSignedNoise(i*0.1+x)*100) -100, ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 153), ofRandom(0, 55), ofRandom(0, 15)); ofCircle( (ofSignedNoise(i*0.1+x)*100), ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 153), ofRandom(0, 55), ofRandom(0, 125)); ofCircle( (ofSignedNoise(i*0.1+x)*100) +100, ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 13), ofRandom(0, 155), ofRandom(0, 125)); ofCircle( (ofSignedNoise(i*0.1+x)*100) +200, ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 130), ofRandom(0, 100), ofRandom(0, 59)); ofCircle( (ofSignedNoise(i*0.1+x)*100) +300, ofSignedNoise((i+1)*0.1+x)*500, 1); } for (int i=0; i<3000; i++) { ofSetColor(ofRandom(0, 90), ofRandom(0, 50), ofRandom(0, 90)); ofCircle( (ofSignedNoise(i*0.1+x)*100) +400, ofSignedNoise((i+1)*0.1+x)*500, 1); } ofPopMatrix(); x += 0.001; // particles.publishScreen(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofClear(0,0,0,0); shader->begin(); shader->setUniform1f("time", ofGetElapsedTimef()); shader->setUniform2f("size", ofVec2f(ofGetWindowSize())); shader->setUniform2f("mouse", ofVec2f(ofGetMouseX(), ofGetMouseY())); ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight()); shader->end(); }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(0); ofSetVerticalSync(true); ofSetFrameRate(60); // make 50 particles up front! for( int i=0; i<50; i++ ){ addParticle(ofGetWindowSize()/2); } }
void Particle::setup( ofVec2f rVel ){ vel = rVel; age = 0; lifespan = ofRandom(450, 650); pos = ofGetWindowSize() / 2.0; pos.x = ofRandom(ofGetWindowWidth()); pos.y = ofRandom(0,10); bIsDead = false; };
void Particle::setup( ofVec2f rVel ){ particleImage.loadImage("particle2.png"); vel = rVel; age = 0; particleColor = ofColor(ofRandom(100,255), ofRandom(100,255), ofRandom(100,255)); lifespan = ofRandom(100, 250); alphaVal = ofRandom(100, 250); pos = ofGetWindowSize() / 2.0; bIsDead = false; };
//-------------------------------------------------------------- void testApp::windowResized(int w, int h){ ofPoint wSize = ofGetWindowSize(); scrW = wSize.x; scrH = wSize.y; printf("w: %d h: %d\n", scrW, scrH); // resets the current gesture's draw area with the new size drawArea = ofRectangle(ofPoint(0, 0), ofGetWindowWidth(), ofGetWindowHeight()); currentGesture.setDrawArea(drawArea); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetFrameRate(60); ofSetVerticalSync(true); mSender.setup("localhost", 12345); ofBackground(0); ballPos = ofGetWindowSize() / 2; vel = ofVec2f(10,0); }
//-------------------------------------------------------------- void testApp::setup(){ pos = ofGetWindowSize()/2; ofSetVerticalSync(true); ofSetBackgroundAuto(false); ofEnableAlphaBlending(); ofBackground(0); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetBackgroundAuto(FALSE); ofEnableAlphaBlending(); ofSetVerticalSync(true); ofBackground(0); pos = ofGetWindowSize() / 2; vel.set( 20, 10, 0 ); mFbo.allocate( ofGetWindowWidth(), ofGetWindowHeight() ); }
void FluidVisualization::draw(){ ofClear(0); if(drawFluid) { glColor3f(1, 1, 1); fluidDrawer.draw(0, 0, ofGetWidth(), ofGetHeight()); } else { // if(ofGetFrameNum()%5==0) fadeToColor(0, 0, 0, 0.01); } if(drawParticles) particleSystem.updateAndDraw(fluidSolver, ofGetWindowSize(), drawFluid); }