예제 #1
0
//--------------------------------------------------------------
void testApp::setup(){
    ofSetVerticalSync(true);
    ofSetFrameRate(60);
    ofSetCircleResolution(30);
    
    //goal
    
    for (int i; i<3; i++) {
        ofImage img;
        img.loadImage("xiaoren"+ofToString(i)+".png");
        xiaoren.push_back(img);
    }
    
//    saver.loadImage("xiaoren.png");
    
    for (int i = 0; i < 30; i++){
        particle * p = new particle();
        goals.push_back(p);
        goals[i]->drawWhat =2;
        goals[i]->setInitialCondition(ofRandom(-ofGetWidth()*0.8,ofGetWidth()*2*0.8),ofRandom(-ofGetWidth()*0.8, ofGetWidth()*2)*0.8,0,0);
        goals[i]->vel.set(0,0);
        goals[i]->saver = & xiaoren[ofRandom(0,2)];
    }
    
    firstTime=ofGetElapsedTimeMillis();
    bStartTime = true;
    bWaitTowin = false;
    bGameStatus = false;
    
	//ship
    shipExplode=false;
    ship.setInitialCondition(ofGetWidth()/2, ofGetHeight()/2, 0, 0);
    ship.drawWhat = 1;
    ship.damping = 0.03f;
    shipImag.loadImage("ship001.png");
    shipImagFire.loadImage("fire.png");
    shipRadiance = 40;
    ship.img = &shipImag;
    ship.imgFire = &shipImagFire;
    //particles
    asteroid.loadImage("asteroid.png");
    for (int i = 0; i < 200; i++){
        
        float scale = ofRandom(1,3);
        particle * p = new particle();
        myParticles.push_back(p);
        myParticles[i]->pos.set(ofRandom(-ofGetWidth(),ofGetWidth()*2),ofRandom(-ofGetWidth(),ofGetWidth()*2));
        myParticles[i]->vel.set(0,0);
        myParticles[i]->asteroid =& asteroid;
        myParticles[i]->scale = scale;
    }
    shield=3;
    //bg
    backgroundImage.loadImage("universe.jpg");
    bgPos.set(0, 0);
    bgMusic.loadSound("backgroundMusic.mp3");
    bgMusic.setLoop(true);
    bgMusic.play();
    bgMusic.setVolume(1.5);
    //text
    verdana.loadFont("Visitor-TT1--BRK-.ttf", 15);
    verdana2.loadFont("Visitor-TT1--BRK-.ttf", 40);
    score = 0;
}
예제 #2
0
//--------------------------------------------------------------
void ofApp::update(){

	// hide old messages
	for(int i = 0; i < NUM_MSG_STRINGS; i++){
		if(timers[i] < ofGetElapsedTimef()){
			msg_strings[i] = "";
		}
	}

	// check for waiting messages
	while(receiver.hasWaitingMessages()){
		// get the next message
		ofxOscMessage m;
		receiver.getNextMessage(&m);
        
		// check for mouse moved message
		if(m.getAddress() == "/mouse/position"){
			// both the arguments are int32's
			mouseX = m.getArgAsInt32(0);
			mouseY = m.getArgAsInt32(1);
		}
		// check for mouse button message
		else if(m.getAddress() == "/mouse/button"){
			// the single argument is a string
			mouseButtonState = m.getArgAsString(0);
		}
        // check for an image being sent (note: the size of the image depends greatly on your network buffer sizes - if an image is too big the message won't come through ) 
        else if(m.getAddress() == "/image" ){
            ofBuffer buffer = m.getArgAsBlob(0);
            receivedImage.load(buffer);
        }
		else{
			// unrecognized message: display on the bottom of the screen
			string msg_string;
			msg_string = m.getAddress();
			msg_string += ": ";
			for(int i = 0; i < m.getNumArgs(); i++){
				// get the argument type
				msg_string += m.getArgTypeName(i);
				msg_string += ":";
				// display the argument - make sure we get the right type
				if(m.getArgType(i) == OFXOSC_TYPE_INT32){
					msg_string += ofToString(m.getArgAsInt32(i));
				}
				else if(m.getArgType(i) == OFXOSC_TYPE_FLOAT){
					msg_string += ofToString(m.getArgAsFloat(i));
				}
				else if(m.getArgType(i) == OFXOSC_TYPE_STRING){
					msg_string += m.getArgAsString(i);
				}
				else{
					msg_string += "unknown";
				}
			}
			// add to the list of strings to display
			msg_strings[current_msg_string] = msg_string;
			timers[current_msg_string] = ofGetElapsedTimef() + 5.0f;
			current_msg_string = (current_msg_string + 1) % NUM_MSG_STRINGS;
			// clear the next line
			msg_strings[current_msg_string] = "";
		}

	}
}
예제 #3
0
void LightsEditor::draw(float x, float y, float w, float h)
{
    ofPushMatrix();
    ofTranslate(x,y,0);
    ofPushStyle();
    if(data->bShowBgImage) {
		#if !defined(TARGET_RASPBERRY_PI)		
        treeimg[data->currentTree].draw(0,0,editorWidth,editorHeight);
        #endif
    }

    ofSetRectMode(OF_RECTMODE_CENTER);
    unsigned int numLights = data->trees[data->currentTree]->lights.size();
    for(int j=0; j < numLights;j++)
    {
        /* Draw circle */
        ofVec2f pos = data->trees[data->currentTree]->lights.at(j)->getPosition();
        ofNoFill();
        ofSetLineWidth(3);
        if(data->currentLight == j) {
            ofSetColor(0,0,255);
            if(data->bEditMode) {
                data->trees[data->currentTree]->lights.at(j)->setColour(ofColor(255,255,255));
                data->trees[data->currentTree]->lights[j]->setBrightness(data->brightness);
            }
        }
        else {
            ofSetColor(100,100,100);
            if(data->bEditMode) {
                data->trees[data->currentTree]->lights.at(j)->setColour(ofColor(0,0,0));
                data->trees[data->currentTree]->lights[j]->setBrightness(data->brightness);
            }
        }
        ofDrawCircle(pos,circleRadius);

        /* draw lighth number */
        ofSetHexColor(0xff3355);
        float w = 10.0f + lightNum.stringWidth(ofToString(j+1));
        lightNum.drawString(ofToString(j+1),pos.x - w,pos.y + circleRadius);

        /* draw connecting grey lines */
        ofSetColor(100,100,100);
        ofSetLineWidth(1);
        if(j+1 < numLights-1) {
            ofVec2f pos2 = data->trees[data->currentTree]->lights.at(j+1)->getPosition();
            ofDrawLine(pos.x,pos.y,pos2.x,pos2.y);
        }

        /* Draw LEDs */
        for(int k=0; k < data->trees[data->currentTree]->lights.at(j)->pixels.size(); k++)
        {
            ofVec2f pixpos = data->trees[data->currentTree]->lights.at(j)->pixels[k]->getPosition();
            ofColor c = data->trees[data->currentTree]->lights.at(j)->pixels[k]->getColour();
            float b = data->trees[data->currentTree]->lights.at(j)->pixels[k]->getBrightness();
            ofSetColor(c.r * b, c.g * b, c.b * b);
            ofFill();
            ofDrawRectangle(pixpos,data->pixelWidth,data->pixelWidth);
        }
    }

    ofSetColor(255);
    ofDrawBitmapString("Name = " + data->trees[data->currentTree]->getName()+" Tree = "+ofToString(data->currentTree)+"  Light Id= "+ofToString(data->currentLight) ,20,ofGetHeight()-20);

    ofPopStyle();
    ofPopMatrix();

}
예제 #4
0
//--------------------------------------------------------------
void testApp::draw(){

	//-----
	// draw image
	if (!this->recorder.getIsRecording()) {
		if (this->selectionView.isAllocated()) {
			this->selectionView.draw(ofGetCurrentViewport());
		} else {
			this->grabber.draw(0,0, ofGetWidth(), ofGetHeight());
		}
	}
	//-----

	timeStart = this->recorder.getFirstTimestamp();
	timeWindow = MAX(this->recorder.getDuration(), 1);

	//----
	//draw frame ticks
	ofPushStyle();
	ofEnableAlphaBlending();
	ofSetColor(ofColor(255, 100));
	for (auto &it : recorder) {
		float position = it.first;
		position -= timeStart;
		position /= timeWindow;
		position *= ofGetWidth();
		ofLine(position, ofGetHeight() - 150, position, ofGetHeight() - 50);
	}	
	ofPopStyle();
	//-----


	//-----
	//draw selection
	ofPushStyle();
	{
		float x = selectionTimestamp;
		x -= timeStart;
		x /= timeWindow;
		x *= ofGetWidth();
		
		float width = selectionDuration;
		width *= ofGetWidth() / (float) timeWindow;

		ofSetColor(ofColor(255, 100));
		ofSetLineWidth(0);
		ofRect(x, ofGetHeight() - 150, width, 200);

		ofSetLineWidth(1.0f);
		ofSetColor(ofColor(255, 200));
		ofLine(x, ofGetHeight() - 150, x, ofGetHeight());
	}
	ofPopStyle();
	//-----


	//-----
	//draw time ticks

	//find scale of time
	int timeScale = floor(log((float) timeWindow) / log(10.0f) + 0.5f);
	double timeScaleMinor = pow(10, timeScale - 2);

	double firstTick = floor(timeStart / timeScaleMinor) * timeScaleMinor;
	double time = firstTick;
	int i = 0;
	while (time < timeStart + timeWindow) {
		//convert to screen space
		float x = (time - timeStart) / timeWindow;
		x *= ofGetWidth();

		float height;
		float y2;
		if (i % 10 == 0) {
			height = 10.0f;
			string label;
			if (timeScale >= 6) {
				label = ofToString((time - timeStart) / 1e6, 2) + "s";
			} else if (timeScale >= 3) {
				label = ofToString((time - timeStart) / 1e3, 2) + "ms";
			} else {
				label = ofToString((time - timeStart) , 2) + "us";
			}
			ofDrawBitmapString(label, x, ofGetHeight() - 3);
			y2 = ofGetHeight() - 3.0f;
		} else if (i % 5 == 0) {
			height = 5.0f;
			y2 = ofGetHeight() - 15.0f;
		} else {
			height = 2.0f;
			y2 = ofGetHeight() - 18.0f;
		}
		ofLine(x, ofGetHeight() - 20.0f, x, y2);

		time += timeScaleMinor;
		i++;
	}
	//
	//-----


	//-----
	// draw pipet selections
	ofPushStyle();
	for (auto pipet : pipets) {
		auto drawLocation = pipet * ofVec2f(ofGetWidth(), ofGetHeight());

		//background
		ofSetColor(0, 100);
		ofRect(drawLocation.x, drawLocation.y, 24, 20);

		//number
		ofSetColor(255);
		if (recorder.count(this->selectionTimestamp) > 0) {
			auto value = this->getValue(this->selectionTimestamp, pipet);
			ofDrawBitmapString(ofToString((int) value), drawLocation.x + 2, drawLocation.y + 18);
		}

		//line
		ofLine(drawLocation.x, drawLocation.y, drawLocation.x, drawLocation.y + 20);

		//other lines
		ofLine(drawLocation.x, drawLocation.y - 3, drawLocation.x, drawLocation.y - 10);
		ofLine(drawLocation.x - 3, drawLocation.y, drawLocation.x - 10, drawLocation.y);
		ofLine(drawLocation.x + 3, drawLocation.y, drawLocation.x + 10, drawLocation.y);

	}
	ofPopStyle();
	//-----

}
예제 #5
0
void demoAdvanced::draw( ) {

    int tx = 0;
    int ty = 0;
    
    ofBackground( 0, 0, 0 );
    
    // quaternion
    ofPushMatrix();

        ofTranslate( ofGetWidth() * 0.5f, ofGetHeight() * 0.5f, -200 );
        
        ofNoFill();
        ofSetColor( 255,255,255 );
        float rotationAmount;
        ofVec3f rotationAngle;
        quaternion.getRotate(rotationAmount, rotationAngle);
        ofRotate(rotationAmount, rotationAngle.x, rotationAngle.y, rotationAngle.z);
        ofBox( 0,0,0, 100, 100, 100 );
        
        ofSetColor( 255,0,0 );
        ofLine( 0,0,0, 100,0,0 );
        ofSetColor( 0,255,0 );
        ofLine( 0,0,0, 0,100,0 );
        ofSetColor( 0,0,255 );
        ofLine( 0,0,0, 0,0,100 );
    
    ofPopMatrix();
    
    // matrix 4x4
    ofPushMatrix();

        ofTranslate( ofGetWidth() * 0.5f, ofGetHeight() * 0.5f, -200 );
        
        ofNoFill();
        ofSetColor( 255,255,255 );
        
        ofMultMatrix( mat );
        ofBox( 0,0,0, 200, 200, 200 );
        
        ofSetColor( 255,0,0 );
        ofLine( 0,0,0, 100,0,0 );
        ofSetColor( 0,255,0 );
        ofLine( 0,0,0, 0,100,0 );
        ofSetColor( 0,0,255 );
        ofLine( 0,0,0, 0,0,100 );
    
    ofPopMatrix();
    
    
    
    ofSetColor( 255,255,255 );
    ty = 25;
    ofDrawBitmapString( "tweener fps: " + ofToString( _tweener->fps() ), 10, ty ); ty += 15;
    ofDrawBitmapString( "tweener time speed: " + ofToString( _tweener->timespeed() ), 10, ty ); ty += 15;
    ofDrawBitmapString( "tweener inner time: " + ofToString( _tweener->innertime() ), 10, ty ); ty += 15;
    if ( _tweener->running() ) {
        ofDrawBitmapString( "tweener is playing", 10, ty ); ty += 15;
    } else {
        ofDrawBitmapString( "tweener is paused", 10, ty ); ty += 15;
    }
    ofDrawBitmapString( "millis: " + ofToString( ofGetElapsedTimeMillis() ), 10, ty ); ty += 15;
    ofDrawBitmapString( "of fps: " + ofToString( ofGetFrameRate() ), 10, ty ); ty += 15;
    
    ofSetColor( 255,255,100 );
    stringstream ss;
    for ( int i = 1; i < lognum; ++i ) {
        ss << logs[ i ] << endl;
    }
    ofDrawBitmapString( ss.str(), 300, 25 );
    
}
void ofxSimpleGuiQuadWarp::loadFromXML(ofxXmlSettings &XML) {
	for(int i=0; i<4; i++) {
		pts[i].x = XML.getValue(controlType + "_" + key + ":values_" + ofToString(i) + "_x", pts[i].x);
		pts[i].y = XML.getValue(controlType + "_" + key + ":values_" + ofToString(i) + "_y", pts[i].y);
	}
}
void TownDashboardRenderer::draw()
{
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    //type
    _typeLayerFbo.begin();
    
    ofClear(0, 0, 0, 0);
    ofBackground(0, 0, 0, 0);
    
    searchingStringImage.draw(0, 0);
    ofPushMatrix();

    ofSetColor(0,255,255);
    int maxVisibleCharacters = 14;
    string subString = _townName.length() > maxVisibleCharacters ? _townName.substr(0, maxVisibleCharacters) : _townName;
    if (_townName.length() <= (maxVisibleCharacters))
    {
        int insertWs = maxVisibleCharacters - _townName.length() - 1;
        for(int i = 0; i<insertWs; i++)
        {
            subString.push_back('p');
        }
    }
    else{
        subString += "...";
        _townName = subString;// + "...";
    }
    ofRectangle fullRect = font.getStringBoundingBox(subString, 0, 0);
    int p = 0;//running count
    ofRectangle runningStringDimensions;
    
    float debugXPos = 2600.0f;
    
    for(char &c : _townName)
    {
        int nVal = min(p + 1, (int)subString.length());
        
        string runningString = subString.substr(0, nVal);
        runningStringDimensions = font.getStringBoundingBox(runningString, 0, 0);
        string thisCharString = ofToString(c);
        ofRectangle thisCharDimensions = font.getStringBoundingBox(thisCharString, 0, 0);
        
        float diff = runningStringDimensions.width - thisCharDimensions.width;
        float debugWidth = fullRect.width;
        float dPos = diff / fullRect.width;
        ofVec2f positionOnCurve = spline2D.sampleAt(dPos);
        ofVec2f tangent = getTangent(dPos, spline2D);
        float rot = atan2(tangent.y, tangent.x) * RAD_TO_DEG;
        
        ofPushMatrix();
        
        ofTranslate(positionOnCurve.x, positionOnCurve.y);
        ofRotate(rot, 0, 0, 1);
        font.drawString(thisCharString, 0, 0);
        
        ofPopMatrix();
        
        if(_debugMode)
        {
            //debug stuff off screen
            ofSetColor(255, 0, 255);
            ofDrawRectangle(debugXPos, p * 100, runningStringDimensions.width, runningStringDimensions.height);
            ofSetColor(0, 255, 0);
            ofDrawRectangle(debugXPos + diff, runningStringDimensions.height + (p * 100), thisCharDimensions.width, 3000);
            ofSetColor(0, 0, 0);
            font.drawString(runningString, debugXPos, 50 + (p * 100));
        }
        
        ofPopMatrix();
        ++p;
        
    }
    ofSetColor(255);
    searchingStringImage.draw(0, 0);
    _typeLayerFbo.end();
    
    //drawn the type
    //black pass
    _blackPassFbo.begin();
    ofClear(0, 0, 0, 255);
    ofBackground(0, 0, 0, 255);
    
    _typeLayerFbo.draw(0, 0);
    
    _blackPassFbo.end();
    
    //glow
    glow.clear();
    glow << _blackPassFbo;
    
    
    
    _glowPassFbo.begin();
    ofClear(0, 0, 0);
    ofBackground(0, 0, 0);
    ofRectangle r = ofRectangle(0, 0, PRINT_DIMENSIONS_WIDTH, PRINT_DIMENSIONS_HEIGHT);
    glow.ofxFXObject::draw(r);
    _glowPassFbo.end();
    
    //final render
    _exportFbo.begin();
    
    ofClear(0, 0, 0);
    ofBackground(0, 0, 0);
//    backgroundImage.draw(0, 0);
    blendImage.draw(0, 0);
    _typeLayerFbo.draw(0, 0);

    ofEnableBlendMode(OF_BLENDMODE_ADD);

    _glowPassFbo.draw(0, 0);
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    
    _exportFbo.end();
    
}
예제 #8
0
void ofLogger::enableFileRotationMonths(unsigned int months){
	fileChannel->setProperty("rotation", ofToString(months)+" months");
}
예제 #9
0
void ofLogger::enableFileRotationSize(unsigned int sizeKB){
	fileChannel->setProperty("rotation", ofToString(sizeKB)+" K");
}
예제 #10
0
void ofLogger::enableFileRotationHours(unsigned int hours){
	fileChannel->setProperty("rotation", ofToString(hours)+" hours");
}
예제 #11
0
void ofLogger::enableFileRotationDays(unsigned int days){
	fileChannel->setProperty("rotation", ofToString(days)+" days");
}
예제 #12
0
//-----------------------------------------------------------------------
void ofLogger::enableFileRotationMins(unsigned int minutes){
	fileChannel->setProperty("rotation", ofToString(minutes)+" minutes");
}
예제 #13
0
void testApp::animateMesh(vector<ofVec3f> * array) {
    float depth = panel.getValueF("depth");
    float radius = panel.getValueF("radius");
    int maxDays = array->size() / 24;
    ofLog() << "Returned array size: " << ofToString(array->size() );
}
예제 #14
0
void testApp::drawHUD() {
    // Debugging business
    graph.draw(ofGetWindowWidth() - graph.getWidth()/2,0,graph.getWidth()/2,graph.getHeight()/2);
    raleway.drawString(ofToString(panel.getValueI("currentDay")) + " at " + ofToString(panel.getValueI("currentTime")) + "pm", 400, 35);   
}
예제 #15
0
void MpiData::loadCities( string _cvsFile ){
    
    // Declare a File Stream.
    ifstream fileIn;
	
    // Open your text File:
    fileIn.open( ofToDataPath( _cvsFile ).c_str());
	
    // Check if File is open.
    if(fileIn.is_open()) {
        int lineCount = 0;
        
        while(fileIn != NULL) {
            string temp;
            getline(fileIn, temp);
			
            // Skip empty lines.
            if(temp.length() == 0) {
                //cout << "Skip empty line no: " << lineCount << endl;
            }
            // Skip Comment lines.
            else if(ofToString(temp[0]) == "#") {
                //cout << "Skip Comment line no: " << lineCount << endl;
            } else {
                // Split row into cols.
				// formerly was: vector<string> cols = ofSplitString(rows[lineCount], ",");
                vector<string> values = ofSplitString(temp, ",");
				
                if (lineCount > 0){
                    mpiCity newCity;
                    newCity.nId = ofToInt(values[0]);
                    
                    newCity.name = values[1];
                    newCity.state = values[2];
                    
                    newCity.lat = ofToFloat(values[3]);
                    newCity.lon = ofToFloat(values[4]);
                    int stars = ofToInt(values[5]);
                    
                    switch (stars) {
                        case 1:
                            newCity.category = MPI_CITY_LARGEST_CONCENTRATION;
                            break;
                        case 2:
                            newCity.category = MPI_CITY_FASTEST_GROWING;
                            break;
                        case 3:
                            newCity.category = MPI_CITY_ACTIVE_RECRUITING;
                            break;
                    }
                    
                    newCity.bestPerforming = ofToFloat(values[6]);
                    newCity.wellBeing = ofToFloat(values[7]);
                    
                    cities.push_back(newCity);
                }
                
                lineCount++;
            }
        }
    }
}
예제 #16
0
//--------------------------------------------------------------------------------
void ofLogger::setFileRotationMaxNum(unsigned int num){
	fileChannel->setProperty("purgeCount", ofToString(num));
}
예제 #17
0
//--------------------------------------------------------------
void testApp::draw(){
	ofSetColor(255, 255, 255);
    
    ofPushMatrix();
    // draw debug (ie., image, depth, skeleton)
    openNIDevice.drawDebug();
    ofPopMatrix();
    
    ofPushMatrix();
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    
    
    
    // iterate through users
    for (int i = 0; i < openNIDevice.getNumTrackedHands(); i++){
        
        // get a reference to this user
        ofxOpenNIHand & hand = openNIDevice.getTrackedHand(i);
        
        // get hand position
        ofPoint & handPosition = hand.getPosition();
        
        // draw a rect at the position
        ofSetColor(255,0,0);
        ofRect(handPosition.x, handPosition.y, 2, 2);
        
        // set depthThresholds based on handPosition
        ofxOpenNIDepthThreshold & depthThreshold = openNIDevice.getDepthThreshold(i); // we just use hand index for the depth threshold index
        
        // draw ROI over the depth image
        ofSetColor(255,255,255);
        depthThreshold.drawROI();
        
        // draw depth and mask textures below the depth image at 0.5 scale
        // you could instead just do pixel maths here for finger tracking etc
        // by using depthThreshold.getDepthPixels() and/or depthThreshold.getMaskPixels()
        // and turn off the textures in the initial setup/addDepthTexture calls
        
        ofPushMatrix();
        ofTranslate(320 * i, 480);
        ofScale(0.5, 0.5);
        depthThreshold.drawDepth();
        depthThreshold.drawMask();
        ofPopMatrix();
        
    }
    
    ofDisableBlendMode();
    ofPopMatrix();
    
    // draw some info regarding frame counts etc
	ofSetColor(0, 255, 0);
	string msg = " MILLIS: " + ofToString(ofGetElapsedTimeMillis()) + " FPS: " + ofToString(ofGetFrameRate()) + " Device FPS: " + ofToString(openNIDevice.getFrameRate());
    
	verdana.drawString(msg, 20, 480 - 20);
    
    
    //--osc
    // display instructions
    ofSetColor(0);
	string buf;
	buf = "sending osc messages to" + string(HOST) + ofToString(PORT);
	ofDrawBitmapString(buf, 10, 20);
	ofDrawBitmapString("move the mouse to send osc message [/mouse/position <x> <y>]", 640, 500);

}
예제 #18
0
//---------------------------------------------------------------------------------
void ofLogger::_log(ofLogLevel logLevel, const string& message, Poco::Logger* theLogger){
	
	string timestamp;
	
	// build the header
	if(bHeader){
	
		Poco::LocalDateTime now;
		
		if(bDate && bTime){
			timestamp += Poco::DateTimeFormatter::format(now, s_dateAndTimeFormat)+" ";
		}
		else if(bDate){
			timestamp += Poco::DateTimeFormatter::format(now, s_dateFormat)+" ";
		}
		else if(bTime){
			timestamp += Poco::DateTimeFormatter::format(now, s_timeFormat)+" ";	
		}
		
		if(bFrameNum){
			timestamp += ofToString(ofGetFrameNum())+" ";
		}
		
		if(bMillis){
			timestamp += ofToString(ofGetElapsedTimeMillis())+" ";
		}
	}
	
	// log
	switch(logLevel){
		case OF_LOG_SILENT:
			break;
			
		case OF_LOG_VERBOSE:
			try{
				theLogger->trace(timestamp+"OF_VERBOSE: "+message);
			}
			catch(...){
				_logDestroyed("OF_VERBOSE: "+message);
			}
			break;
			
		case OF_LOG_DEBUG:
			try{
				theLogger->debug(timestamp+"OF_DEBUG: "+message);
			}
			catch(...){
				_logDestroyed("OF_DEBUG: "+message);
			}
			break;
			
		case OF_LOG_NOTICE:
			try{
				theLogger->notice(timestamp+message);
			}
			catch(...){
				_logDestroyed(message);
			}
			break;

		case OF_LOG_WARNING:
			try{
				theLogger->warning(timestamp+"OF_WARNING: "+message);
			}
			catch(...){
				_logDestroyed("OF_WARNING: "+message);
			}
			break;

		case OF_LOG_ERROR:
			try{
				theLogger->error(timestamp+"OF_ERROR: "+message);
			}
			catch(...){
				_logDestroyed("OF_ERROR: "+message);
			}
			break;
			
		case OF_LOG_FATAL_ERROR:
			try{
				theLogger->fatal(timestamp+"OF_FATAL_ERROR: "+message);
			}
			catch(...){
				_logDestroyed("OF_FATAL_ERROR: "+message);
			}
			break;
	}
}
//--------------------------------------------------------------
void testApp::draw(){
	if( oneShot ){
		ofBeginSaveScreenAsPDF("screenshot-"+ofGetTimestampString()+".pdf", false);
	}
	
	ofSetColor(54);
	ofDrawBitmapString("PDF OUTPUT EXAMPLE", 32, 32);
	if( pdfRendering ){
		ofDrawBitmapString("press r to stop pdf multipage rendering", 32, 92);
	}else{	
		ofDrawBitmapString("press r to start pdf multipage rendering\npress s to save a single screenshot as pdf to disk", 32, 92);
	}
		
		
	ofFill();		
	ofSetColor(54,54,54);
	ofDrawBitmapString("TTF Font embdedded into pdf as vector shapes", 32, 460);
	
	if( oneShot || pdfRendering ){
		font.drawStringAsShapes("Current Frame: ",  32, 500);
		ofSetColor(245, 58, 135);
		font.drawStringAsShapes( ofToString(ofGetFrameNum()), 32 + font.getStringBoundingBox("Current Frame: ", 0, 0).width + 9, 500);
	}else{
		font.drawString("Current Frame: ",  32, 500);	
		ofSetColor(245, 58, 135);		
		font.drawString( ofToString(ofGetFrameNum()), 32 + font.getStringBoundingBox("Current Frame: ", 0, 0).width + 9, 500);		
	}
	
	
	ofSetColor(54,54,54);
	ofDrawBitmapString("Images can also be embedded into pdf", 32, dropZoneRects[0].y - 18);
	
	ofSetRectMode(OF_RECTMODE_CORNER);
	ofNoFill();
	for(int k = 0; k < dropZoneRects.size(); k++){
		ofSetColor(54,54,54);
		ofRect(dropZoneRects[k]);
		ofSetColor(245, 58, 135);		
		ofDrawBitmapString("drop images here", dropZoneRects[k].getCenter().x - 70, dropZoneRects[k].getCenter().y);
	}

	ofSetColor(255);
	for(int j = 0; j < images.size(); j ++){
		if( images[j].width > 0 ){
			
			float tw = 300;
			float th = 200;
			
			if( images[j].getWidth() / images[j].getHeight() < tw / th ){
				tw = th * ( images[j].getWidth() / images[j].getHeight() );
			}else{
				th = tw * ( images[j].getHeight() / images[j].getWidth() );			
			}
			
			images[j].draw(dropZoneRects[j].x, dropZoneRects[j].y, tw, th);
			
		}
	}
	
	//lets draw a box with a trail
	ofSetColor(245, 58, 135);
	
	ofRectangle boxBounds(32, 500, ofGetWidth()-32, 250);
	
	//lets get a noise value based on the current frame
	float noiseX = ofNoise(float(ofGetFrameNum())/600.f, 200.0f);
	float noiseY = ofNoise(float(ofGetFrameNum())/800.f, -900.0f);

	ofNoFill();
	ofBeginShape();
	ofVertexes(boxTrail);
	ofEndShape(false);
	
	ofFill();
	ofSetRectMode(OF_RECTMODE_CENTER);

	ofPushMatrix();
		float x = ofMap( noiseX, 0, 1, boxBounds.x, boxBounds.x + boxBounds.width, true);
		float y = ofMap( noiseY, 0, 1, boxBounds.y, boxBounds.y + boxBounds.height, true);

		ofTranslate(x, y, 0);
		ofRotate(angle);
		ofRect(0, 0, 30, 30);
	ofPopMatrix();	
	
	if( boxTrail.size() == 0 || ( boxTrail.back() - ofPoint(x, y) ).length() > 1.5 ){
		boxTrail.push_back(ofPoint(x, y));
	}
	
	if(boxTrail.size() > 800 ){
		boxTrail.erase(boxTrail.begin(), boxTrail.begin()+1);
	}
	
	if( oneShot ){
		ofEndSaveScreenAsPDF();
		oneShot = false;
	}	
}
//------------------------------------
void ofxRemoteCameraClient::threadedFunction(){
	string msg;
	while (isThreadRunning()) {
		if(connected){
			/*********SENDING THE REQUEST*********/
			if(changeRequested){
				requestedImageType=tmpImageType;
				compressionQuality=tmpCompressionQuality;
				requestedWidth=tmpW;
				requestedHeight=tmpH;
				changeRequested=false;
			}
			msg.clear();
			msg=msg+ofToString(requestedWidth, 0)+SIZE_SEPARATOR+ofToString(requestedHeight, 0)+DATA_SEPARATOR;
			msg=msg+ofToString(compressionQuality,0)+DATA_SEPARATOR;
			msg=msg+ofToString(requestedImageType, 0)+DATA_SEPARATOR;
			
			while (msg.size()<MSG_SIZE) {
				msg=msg+"0";
			}
			
			if(verbose)
				cout << "SENDING REQUEST: "<<msg<<"\n";	
			
			if(sendData(client->TCPClient,(unsigned char*)msg.c_str(), MSG_SIZE)>0){
				if(verbose)cout << "SIZE:";	
				char s2[MSG_SIZE];
				if(receiveData(client->TCPClient,(unsigned char*)s2,MSG_SIZE)>0){
					intSize = ofToInt( string( s2 ) );
					if(verbose)cout<< " "<< intSize<<"\n";
					lock();
					if(verbose)cout <<"START RECEIVING DATA\n";
					if(receiveData(client->TCPClient,auxPixels,intSize)>0) {
						if(compressionQuality<NO_COMPRESSION){
							decompress(auxPixels,intSize, requestedWidth, requestedHeight,getPixelSize(requestedImageType));
							unsigned char *tmp=(unsigned char*)auxPixels;
							auxPixels=compressedData;
							compressedData=tmp;
						}
						if(verbose)
							cout << "DATA RECIEVED AND COMPRESSED\n";
						newData=connected;
						unlock();
						continue;
					}
					unlock();
				}
			}
			cout<<"Error!!!\n";
			connected=false;
		}
		else{
			setupConnection();
			if(!isConnected()){
				cout << "Connection refused. Sleeping....";
				#ifdef TARGET_WIN32 
					Sleep(SLEEPING_TIME);	
				#else 
					sleep(SLEEPING_TIME);
				#endif
				cout << "done\n";
			}
			else {
				cout << "Connected to "<<address<<":"<<port<<"\n";
			}

		}
	}
}
//--------------------------------------------------------------
bool ofxVideoRecorder::setupCustomOutput(int w, int h, float fps, int sampleRate, int channels, string outputString, bool sysClockSync, bool silent){
    if(bIsInitialized)
    {
        close();
    }

    bIsSilent = silent;
    bSysClockSync = sysClockSync;

    bRecordAudio = (sampleRate > 0 && channels > 0);
    bRecordVideo = (w > 0 && h > 0 && fps > 0);
    bFinishing = false;

    videoFramesRecorded = 0;
    audioSamplesRecorded = 0;

    if(!bRecordVideo && !bRecordAudio) {
        ofLogWarning() << "ofxVideoRecorder::setupCustomOutput(): invalid parameters, could not setup video or audio stream.\n"
        << "video: " << w << "x" << h << "@" << fps << "fps\n"
        << "audio: " << "channels: " << channels << " @ " << sampleRate << "Hz\n";
        return false;
    }
    videoPipePath = "";
    audioPipePath = "";
    pipeNumber = requestPipeNumber();
    if(bRecordVideo) {
        width = w;
        height = h;
        frameRate = fps;

        // recording video, create a FIFO pipe
        videoPipePath = ofFilePath::getAbsolutePath("ofxvrpipe" + ofToString(pipeNumber));
        if(!ofFile::doesFileExist(videoPipePath)){
            string cmd = "bash --login -c 'mkfifo " + videoPipePath + "'";
            system(cmd.c_str());
            // TODO: add windows compatable pipe creation (does ffmpeg work with windows pipes?)
        }
    }

    if(bRecordAudio) {
        this->sampleRate = sampleRate;
        audioChannels = channels;

        // recording video, create a FIFO pipe
        audioPipePath = ofFilePath::getAbsolutePath("ofxarpipe" + ofToString(pipeNumber));
        if(!ofFile::doesFileExist(audioPipePath)){
            string cmd = "bash --login -c 'mkfifo " + audioPipePath + "'";
            system(cmd.c_str());

            // TODO: add windows compatable pipe creation (does ffmpeg work with windows pipes?)
        }
    }

    stringstream cmd;
    // basic ffmpeg invocation, -y option overwrites output file
    cmd << "bash --login -c '" << ffmpegLocation << (bIsSilent?" -loglevel quiet ":" ") << "-y";
    if(bRecordAudio){
        cmd << " -acodec pcm_s16le -f s16le -ar " << sampleRate << " -ac " << audioChannels << " -i " << audioPipePath;
    }
    else { // no audio stream
        cmd << " -an";
    }
    if(bRecordVideo){ // video input options and file
        cmd << " -r "<< fps << " -s " << w << "x" << h << " -f rawvideo -pix_fmt " << pixelFormat <<" -i " << videoPipePath << " -r " << fps;
    }
    else { // no video stream
        cmd << " -vn";
    }
    cmd << " "+ outputString +"' &";

    // start ffmpeg thread. Ffmpeg will wait for input pipes to be opened.
    ffmpegThread.setup(cmd.str());

    // wait until ffmpeg has started
    while (!ffmpegThread.isInitialized()) {
        usleep(10);
    }

    if(bRecordAudio){
        audioThread.setup(audioPipePath, &audioFrames);
    }
    if(bRecordVideo){
        videoThread.setup(videoPipePath, &frames);
    }

    bIsInitialized = true;
    bIsRecording = false;
    bIsPaused = false;

    startTime = 0;
    recordingDuration = 0;
    totalRecordingDuration = 0;

    return bIsInitialized;
}
예제 #22
0
void mpeServerTCP::threadedFunction()
{
	while(isThreadRunning()){

		if(shouldTriggerFrame){
			float now = ofGetElapsedTimef();
			float elapsed = (now - lastFrameTriggeredTime);

			//cout << "should trigger frame!" << endl;

			if(elapsed >= 1.0/framerate){

				//cout << "triggered frame with framerate error of " << fabs( elapsed - 1.0/framerate)  << endl;

				string message = "G,"+ofToString(currentFrame);
				if (newMessage){
					message += currentMessage;
					newMessage = false;
					currentMessage = "";
				}

				server.sendToAll(message);

				for(int i = 0; i < connections.size(); i++){
					connections[i].ready = false;
				}

				shouldTriggerFrame = false;
				lastFrameTriggeredTime = now;
				currentFrame++;
			}
		}
		else {

			//check for dead clients
			bool lostConnection = false;
			for(int c = 0; c < numExpectedClients; c++){
				if(connections[c].started && !server.isClientConnected(connections[c].tcpServerIndex)){
					connections[c].started = false;
					lostConnection = true;
				}
			}

			if(allconnected && lostConnection){

				ofLog(OF_LOG_NOTICE, "MPE :: Client Disconnected -- RESET");

				//oops someone left
				printClientStatus();
				currentFrame = 0;
				shouldTriggerFrame = false;
				allconnected = false;

				server.sendToAll("R");
			}

			//cout << "All clients are connected! " << endl;

			for(int i = 0; i < server.getLastID(); i++){

				if(!server.isClientConnected(i)){
					continue;
				}

				string response = server.receive(i);

				if(response == ""){
					continue;
				}

	//			cout << "received a response " << response << endl;

				char first = response.at(0);
				if(first == 'L'){
					//Listener connected
					listeners.push_back(i);
				}
				else if(first == 'S'){
					//that's the start!
					int clientID = ofToInt(response.substr(1,1));
					if(clientID < numExpectedClients){
						vector<string> info = ofSplitString(response, ",", true, true);
						if(connections[clientID].started && currentFrame != 0){
                            //client already started, must have reset...
                            allconnected = false;
                            currentFrame = 0;
                            shouldTriggerFrame = false;
                            server.sendToAll("R");
						}

						connections[clientID].tcpServerIndex = i;
						connections[clientID].started = true;
						connections[clientID].name = info[1];
						cout << "Client ID " << clientID << " with response " << response << endl;
						//TODO: parse name
						printClientStatus();
					}
					else{
						ofLog(OF_LOG_ERROR, "Received Client ID " + ofToString(clientID)  + " out of range");
					}
				}
				else if(first == 'D'){

					if(!allconnected){
						continue;
					}

					vector<string> info = ofSplitString(response, ",", true, true);
					if(info.size() >= 3){
						int clientID = ofToInt(info[1]);
						int fc = ofToInt(info[2]);
						if(fc == currentFrame){
							//todo validate client id
							connections[clientID].ready = true;
							//cout << " client " << clientID << " is ready " << endl;
						}
						if(info.size() > 3){
							newMessage = true;
							for(int i = 3; i < info.size(); i++){
								currentMessage += ":" + info[i];
							}
							//cout << "NEW FORMAT :: MESSSAGE IS " << currentMessage << endl;
						}
					}
					else {
						ofLog(OF_LOG_ERROR, "MPE Server :: Response String " + response + " Invalid size");
					}
				}
			}

			if(!allconnected){
				allconnected = true;
				for(int c = 0; c < connections.size(); c++){
					if(!connections[c].started){
						allconnected = false;
						break;
					}
				}
				if(allconnected){
					shouldTriggerFrame = true;
					cout << "All clients connected!" << endl;
				}
			}
			//All connected and going
			else {
				bool allready = true;
				for(int c = 0; c < connections.size(); c++){
					if(!connections[c].ready){
						allready = false;
						break;
					}
				}
				if(allready){
					shouldTriggerFrame = true;
				}
			}
		}
        ofSleepMillis(5);
	}//end while
}
예제 #23
0
//--------------------------------------------------------------
void testApp::update(){
	this->guiRecordStateLabel->setLabel(Stream::Recorder::toString(this->recorder.getState()));
	this->guiDeviceStateLabel->setLabel(toString(grabber.getDeviceState()));
	this->guiRecordCountLabel->setLabel("Frame count: " + ofToString(this->recorder.size()));

	if (this->toggleRecord != this->recorder.getIsRecording()) {
		if (this->toggleRecord) {
			this->recorder.start();
		} else {
			this->recorder.stop(); 
		}
	}

	if (this->bangClear) {
		this->recorder.clear();
		this->selectionView.clear();
	}

	if (this->bangClearBefore) {
		auto it = this->recorder.lower_bound(this->selectionTimestamp);
		while (it != this->recorder.end()) {
			this->recorder.erase(it);
			it = this->recorder.lower_bound(this->selectionTimestamp);
		}
	}

	if (this->bangClearAfter) {
		auto it = this->recorder.upper_bound(this->selectionTimestamp);
		while (it != this->recorder.end()) {
			this->recorder.erase(it);
			it = this->recorder.upper_bound(this->selectionTimestamp);
		}
	}
	
	if (this->bangSavePipets) {
		ofFile file;
		file.open("pipets.txt", ofFile::WriteOnly, false);
		for (auto it : this->recorder) {
			file << it.first << "\t";

			for (auto pipet : this->pipets) {
				file << (int) this->getValue(it.first, pipet) << "\t";
			}

			file << endl;
		}
		file.close();
	}

	if (!this->recorder.getIsRecording()) {
		this->grabber.update();
	}

	if (this->toggleSave) {
		auto & pixels = this->recorder[this->selectionTimestamp].getPixelsRef();
		ofSaveImage(pixels, ofToString(this->selectionTimestamp) + ".png");
	}

	if (this->toggleProgress && ! this->recorder.empty()) {
		auto nextFrame = this->recorder.upper_bound(this->selectionTimestamp);
		if (nextFrame == this->recorder.end()) {
			nextFrame = this->recorder.begin();
		}
		this->selectionTimestamp = nextFrame->first;
		this->loadSelection();
	} else {
		this->toggleSave = false;
	}
}
예제 #24
0
void ofApp::update()
{
    ofSetWindowTitle(ofToString(ofGetFrameRate()));
}
예제 #25
0
void ofApp::draw()
{
    ofBackground(0);

    cam.begin();

    ofPushMatrix();
    ofTranslate(- ofGetWidth() / 2, - ofGetHeight() / 2, 0);

    ofNoFill();
    ofSetColor(255);

    // Draw all of the points.
    mesh.draw();

    ofFill();
    ofSetColor(255, 255, 0, 80);

    for (std::size_t i = 0; i < searchResults.size(); ++i)
    {
        std::size_t resultIndex = searchResults[i].first;
        float resultDistance = searchResults[i].second;

        DataType& result = points[resultIndex];

        glm::vec3 resultAsPoint(result[0], result[1], result[2]);

        float normalizedDistance = ofMap(resultDistance, radius * radius, 0, 0, 1, true);

        ofSetColor(255, 255, 0, normalizedDistance * 127);

        ofDrawSphere(resultAsPoint, 5);

        if (MODE_NEAREST_N == mode)
        {
            ofSetColor(255, 127);
            ofDrawBitmapString(ofToString(i), resultAsPoint);
        }
    }

    if (MODE_RADIUS == mode)
    {
        ofNoFill();
        ofSetColor(255, 0, 0, 50);

        glm::vec3 fireflyAsPoint(firefly[0], firefly[1], firefly[2]);

        ofDrawSphere(fireflyAsPoint, radius);
    }

    ofPopMatrix();

    cam.end();

    std::stringstream ss;


    if (MODE_RADIUS == mode)
    {
        ss << "SEARCH MODE (space): RADIUS" << std::endl;
        ss << "       RADIUS (-/=): " << radius;
    }
    else
    {
        ss << "SEARCH MODE (space): NEAREST N" << std::endl;
        ss << "    NEAREST N (-/=): " << nearestN;
    }

    ofDrawBitmapStringHighlight(ss.str(), glm::vec2(30, 30));
}
예제 #26
0
파일: screen0.cpp 프로젝트: jaumet/PdV
void screen0::draw(int x, int y){
	// BEGIN DRAW IN FBO
	votesManager::getInstance()->drawFBOBegin();
	ofBackground(0,0,0);
	ofSetColor(0,0,0);
	ofRect(0,0,(ofGetWidth()-666),ofGetHeight());
	float radius = 360;
	int totalScreens = screensManager::getInstance()->getCurrentTotalScreens();
	float partionForScreen = ofDegToRad((360.0f/((float)totalScreens)));
	ofVec2f centerPos = ofVec2f((ofGetWidth()-666)/2,ofGetHeight()/2);
	int partCount = 0;

	// draw part show already
	if(screensManager::getInstance()->getScreenArId()>0){
		ofSetColor(50,50,50);
		ofBeginShape();
		for(int i=0; i<screensManager::getInstance()->getScreenArId()+1; i++){
			float degrees = partionForScreen * (float)i;
			ofVec2f pos = ofVec2f( radius*cos(degrees) , radius*sin(degrees) );
			float radius3 = radius-65;
			ofVec2f point1 = ofVec2f( centerPos.x+(radius3*cos(degrees)) , centerPos.y+(radius3*sin(degrees)) );
			ofVertex(point1.x,point1.y);
		}
		for(int i=screensManager::getInstance()->getScreenArId(); i>=0; i--){
			float degrees = partionForScreen * (float)i;
			ofVec2f pos = ofVec2f( radius*cos(degrees) , radius*sin(degrees) );
			float radius4 = radius+50;
			ofVec2f point2 = ofVec2f( centerPos.x+(radius4*cos(degrees)) , centerPos.y+(radius4*sin(degrees)) ); 
			ofVertex(point2.x,point2.y);
		}
		ofEndShape();
	}
	
	for(int i=0;i<totalScreens;i++){
		// position in circle
		float degrees = partionForScreen * (float)i;
		ofVec2f pos = ofVec2f( radius*cos(degrees) , radius*sin(degrees) );
		
		// Part
		int secondPart = screensManager::getInstance()->getTotalScreensPart1();
		int thirdPart = (screensManager::getInstance()->getTotalScreensPart1()+screensManager::getInstance()->getTotalScreensPart2());
		
		if( i==0 || secondPart==i || thirdPart==i ){
			if( secondPart==i || thirdPart==i ){ ofSetColor(190,190,190); }else{ofSetColor(255,255,255);}
			float radius3 = radius-65;
			float radius4 = radius+50;
			ofVec2f point1 = ofVec2f( centerPos.x+(radius3*cos(degrees)) , centerPos.y+(radius3*sin(degrees)) );
			ofVec2f point2 = ofVec2f( centerPos.x+(radius4*cos(degrees)) , centerPos.y+(radius4*sin(degrees)) ); 
			ofLine( point1.x, point1.y, point2.x, point2.y);
			double angleText = ofRadToDeg(atan2(point2.y-point1.y, point2.x-point1.x));
			// get total screens per part
			int totalScreensThisPart = 0;
			
			ofSetColor(190,190,190);
			if(i==0){
				totalScreensThisPart = screensManager::getInstance()->getTotalScreensPart1();
				partCount = 1;
			}else if(i==secondPart){
				totalScreensThisPart = screensManager::getInstance()->getTotalScreensPart2();
				partCount = 2;
			}else if(i==thirdPart){
				totalScreensThisPart = screensManager::getInstance()->getTotalScreensPart3();
				partCount = 3;
			}
			
			string partText = translateManager::getInstance()->t("Part");
			partText[0] = toupper(partText[0]);
			string textThisPart = partText+" "+ofToString(partCount)+"["+ofToString(totalScreensThisPart)+"]";
			int withTextThisPart = fontManager::getInstance()->getPixelFont()->stringWidth(textThisPart);
			// draw text of the part
			ofPushMatrix();
			ofTranslate(point1.x,point1.y);	
			ofRotate(angleText);
			ofTranslate(-5-withTextThisPart,0);
			fontManager::getInstance()->getPixelFont()->drawString(textThisPart,0,0);
			ofPopMatrix();
			
		}
		
		// type by colors
		string typeScreen = screensManager::getInstance()->getIdScreenType(i);
		if(typeScreen=="question"){
			ofSetColor(5,143,249);
		}else if(typeScreen=="debate"){
			ofSetColor(255,255,0);
		}else if(typeScreen=="statement"){
			ofSetColor(255,0,240);
		}else{
			ofSetColor(255,0,0);
		}
		
		// represent
		ofEllipse(centerPos.x+pos.x,centerPos.y+pos.y,2,2);
		
		float radius2 = radius+10;
		ofVec2f pos2 = ofVec2f( radius2*cos(degrees) , radius2*sin(degrees) );
		ofLine(centerPos.x+pos.x,centerPos.y+pos.y,centerPos.x+pos2.x,centerPos.y+pos2.y);
		
		// error Link
		if( screensManager::getInstance()->getScreenHasBrokenLinks(i) ){
			ofSetColor(255,0,0);
			float radius3 = radius-5;
			float radius4 = radius-150;
			ofVec2f pos3 = ofVec2f( radius3*cos(degrees) , radius3*sin(degrees) );
			ofVec2f pos4 = ofVec2f( radius4*cos(degrees) , radius4*sin(degrees) );
			ofVec2f point1 = ofVec2f(centerPos.x+pos3.x,centerPos.y+pos3.y);
			ofVec2f point2 = ofVec2f(centerPos.x+pos4.x,centerPos.y+pos4.y);
			ofLine(point1.x,point1.y,point2.x,point2.y);

			string idScreen = ofToString(screensManager::getInstance()->getIdScreen(i));
		
			double angleText = ofRadToDeg(atan2(point2.y-point1.y, point2.x-point1.x))+180.0f;
			//int stringSize = fontManager::getInstance()->getPixelFont()->stringWidth(idScreen);
			ofVec2f posText = ofVec2f(centerPos.x+pos4.x,centerPos.y+pos4.y);
			ofPushMatrix();
			ofTranslate(posText.x,posText.y);	
			ofRotate(angleText);
			ofTranslate(0,-2);
			fontManager::getInstance()->getPixelFont()->drawString(idScreen,0,0);
			ofPopMatrix();
		}
		// show current screen
		if(screensManager::getInstance()->getScreenArId()==i){
			ofSetColor(255,255,255);
			float radius3 = radius-65;
			float radius4 = radius+50;
			ofVec2f pos3 = ofVec2f( radius3*cos(degrees) , radius3*sin(degrees) );
			ofVec2f pos4 = ofVec2f( radius4*cos(degrees) , radius4*sin(degrees) );
			ofVec2f point1 = ofVec2f(centerPos.x+pos3.x,centerPos.y+pos3.y);
			ofVec2f point2 = ofVec2f(centerPos.x+pos4.x,centerPos.y+pos4.y);
			ofLine(point1.x,point1.y,point2.x,point2.y);

			string idScreen = ofToString(screensManager::getInstance()->getIdScreen(i));
			double angleText = ofRadToDeg(atan2(point2.y-point1.y, point2.x-point1.x));
			int stringSize = fontManager::getInstance()->getPixelFont()->stringWidth(idScreen);
			ofVec2f posText = ofVec2f(centerPos.x+pos3.x,centerPos.y+pos3.y);
			ofPushMatrix();
			ofTranslate(posText.x,posText.y);	
			ofRotate(angleText);
			ofTranslate(60-stringSize,-5);
			fontManager::getInstance()->getPixelFont()->drawString(idScreen,0,0);
			ofPopMatrix();
		}

	}
	// Title
	ofSetColor(255,255,255);
	string textTitle = "Screens PdV";
	int stringHalfSize = fontManager::getInstance()->getPixelFont()->stringWidth(textTitle)/2;
	fontManager::getInstance()->getPixelFont()->drawString(textTitle,(ofGetWidth()-666)/2-stringHalfSize,ofGetHeight()/2);
	
	// Total screens
	ofSetColor(90,90,90);
	string totalScreensStr = "total screens:"+ofToString(totalScreens);
	totalScreensStr[0] = toupper(totalScreensStr[0]);
	stringHalfSize = fontManager::getInstance()->getPixelFont()->stringWidth(totalScreensStr)/2;
	fontManager::getInstance()->getPixelFont()->drawString(totalScreensStr,(ofGetWidth()-666)/2-stringHalfSize,(ofGetHeight()/2)+15);

	// Total errors
	if( settingsManager::getInstance()->getDebugMode() ){
		int totalErrors = screensManager::getInstance()->getTotalXMLErrors();
		if(totalErrors>0){
			ofSetColor(255,0,0);
			stringHalfSize = fontManager::getInstance()->getPixelFont()->stringWidth("Total XML errors:"+ofToString(totalErrors))/2;
			fontManager::getInstance()->getPixelFont()->drawString("Total XML errors:"+ofToString(totalErrors),(ofGetWidth()-666)/2-stringHalfSize,(ofGetHeight()/2)+30);
		}else{
			ofSetColor(0,255,0);
			stringHalfSize = fontManager::getInstance()->getPixelFont()->stringWidth("There is no XML errors")/2;
			fontManager::getInstance()->getPixelFont()->drawString("There is no XML errors",(ofGetWidth()-666)/2-stringHalfSize,(ofGetHeight()/2)+30);
		}
	}

	ofPushMatrix();
	ofTranslate(20,-20);
	string typeScreen = "";
	// 
	ofSetColor(5,143,249);
	ofRect(15,ofGetHeight()-65,10,10);
	typeScreen = "question";
	fontManager::getInstance()->getPixelFont()->drawString(typeScreen,30,ofGetHeight()-55);
	
	ofSetColor(255,255,0);
	ofRect(15,ofGetHeight()-50,10,10);
	typeScreen = "debate";
	fontManager::getInstance()->getPixelFont()->drawString(typeScreen,30,ofGetHeight()-40);
	
	ofSetColor(255,0,240);
	ofRect(15,ofGetHeight()-35,10,10);
	typeScreen = "statement or text";
	fontManager::getInstance()->getPixelFont()->drawString(typeScreen,30,ofGetHeight()-25);
	
	if( settingsManager::getInstance()->getDebugMode() ){
		ofSetColor(255,0,0);
		ofRect(15,ofGetHeight()-20,10,10);
		typeScreen = "errors";
		fontManager::getInstance()->getPixelFont()->drawString(typeScreen,30,ofGetHeight()-10);
	}
	ofPopMatrix();

	
	// END DRAW IN FBO
	votesManager::getInstance()->drawFBOEnd();

	// Draw FBO
	ofSetColor(255,255,255);
	votesManager::getInstance()->drawFBO(x,y);
}
예제 #27
0
//--------------------------------------------------------------
bool testApp::loadNewProject(){
	allLoaded = false;
	ofSystemAlertDialog("Select Someone's Name");
	ofFileDialogResult r;
	r = ofSystemLoadDialog("Get Directory", true);
	if(!r.bSuccess){
		return false;
	}
		
	string currentMediaFolder = r.getPath();	
	
	ofDirectory compBin(currentMediaFolder + pathDelim + "compositions"+pathDelim);
	if(!compBin.exists()){
		compBin.create(true);
	}	
	compBin.listDir();
	
	int compNumber = compBin.numFiles();
	currentCompositionDirectory = currentMediaFolder + pathDelim+"compositions"+pathDelim+"comp" + ofToString(compNumber) + pathDelim;
	currentCompIndex = compNumber;
	
	if(!loadAssetsFromCompositionDirectory(currentMediaFolder)){
		return false;
	}
	
	saveComposition();
	refreshCompButtons();
	loadTimelineFromCurrentComp();
	
	allLoaded = true;
	return true;
}
예제 #28
0
void MpiData::loadYear( int _year, string _cvsFile ){

    // Declare a File Stream.
    ifstream fileIn;
	
    // Open your text File:
    fileIn.open( ofToDataPath( _cvsFile ).c_str());
	
    vector<mpiCitySample> newYearSample;
    
    // Check if File is open.
    if(fileIn.is_open()) {
        int lineCount = 0;
        
        while(fileIn != NULL) {
            string temp;
            getline(fileIn, temp);
			
            // Skip empty lines.
            if(temp.length() == 0) {
                //cout << "Skip empty line no: " << lineCount << endl;
            }
            // Skip Comment lines.
            else if(ofToString(temp[0]) == "#") {
                //cout << "Skip Comment line no: " << lineCount << endl;
            } else {
                // Split row into cols.
				// formerly was: vector<string> cols = ofSplitString(rows[lineCount], ",");
                vector<string> values = ofSplitString(temp, ",");
				
                if (lineCount > 0){
                    
                    mpiCitySample newSample;
                    newSample.nId = ofToInt(values[0]);
                    newSample.pop = ofToInt(values[2]);             //  Number: Total pop
                    newSample.popImm = ofToInt(values[3]);          //  Number:  Immigrants
                    newSample.popImmShare = ofToFloat(values[4]);   //  Immigrant share (%) (???)
                    newSample.recArr = ofToFloat(values[5]);        //  Recent arrivals (%) of all immigrants
                    
                    //  Education
                    //
                    newSample.noDegreeImm = ofToFloat(values[6]);    //Percent: No high school degree   Immigrants
                    newSample.hsDegreeImm = ofToFloat(values[7]);    //Percent: High school/AA degree  Immigrants
                    newSample.baDegreeImm = ofToFloat(values[8]);    //Percent: BA/higher  Immigrants
                    newSample.noDegreeNat = ofToFloat(values[9]);   //Percent: No high school degree  Native born
                    newSample.hsDegreeNat = ofToFloat(values[10]);    //Percent: High school/AA degree Native born
                    newSample.baDegreeNat = ofToFloat(values[11]);    //Percent: BA/higher Native born
                    
                    //  Employment
                    //
                    newSample.employedTotal = ofToInt(values[12]);  //Number:  Employed
                    newSample.employedImm = ofToInt(values[13]);    //Number:  Imm  Employed
                    newSample.employedNat = ofToInt(values[14]);    //Number:  Natives  Employed
                    
                    newSample.employedImmShare = ofToFloat(values[15]);   // Imm share among all empl (%) (???)
                    newSample.unEmployment = ofToFloat(values[16]);       //Unemployment rate (%)
                    
                    //  Financial
                    //
                    newSample.poverty = ofToFloat(values[17]);        //Poverty rate (%)
                    newSample.homeOwners = ofToFloat(values[18]);     //Rate of home ownership (%)
                    
                    //  Ethnic/Cultural
                    //
                    newSample.black = ofToFloat(values[19]);          //Percent: Black
                    newSample.asian = ofToFloat(values[20]);          //Percent: Asian
                    newSample.latino = ofToFloat(values[21]);         //Percent: Latino
                    newSample.nonWhite = ofToFloat(values[22]);       //Percent: Non-white
                    newSample.nonEnglSpk = ofToFloat(values[23]);     //Percent: Speak other lang (than English)
                    
                    newSample.creativeClass = ofToFloat(values[24]);
                    
                    newYearSample.push_back(newSample);
                    
                }
                
                lineCount++;
            }
        }
        
        //  Check between witch years need to be inserted ( sort )
        //
        int offSet = 0;
        for (int i = 0; i < years.size(); i++){
            if ( _year > years[i] )
                offSet = i+1;
        }
        
        years.insert(years.begin()+offSet, _year);
        samples.insert(samples.begin()+offSet,newYearSample);
        
    }
}
예제 #29
0
bool ramTSVCoder::encode(ramSession &src)
{
	if (src.getNumFrames() <= 0)
	{
		cout << "session seems not to have any data to save." << endl;
		return false;
	}
	
	ofBuffer buf;
	
	ramNodeArray& sample = src.getFrame(0);
	
	
	const string timestampStr = ofGetTimestampString("%Y.%m.%d_%H.%M.%S");
	const string address = sample.isActor() ? RAM_OSC_ADDR_ACTOR : RAM_OSC_ADDR_RIGID_BODY;
	const string entityName = sample.getName() + " " + timestampStr;
	const string numJoints = ofToString( sample.getNumNode() );
	
	for(int i=0; i<src.getNumFrames(); i++)
	{
		ramNodeArray &nodeArray = src.getFrame(i);
		stringstream frame;
		frame << address << "\t" << entityName << "\t" << numJoints << "\t";
		
		for(int j=0; j<nodeArray.getNumNode(); j++)
		{
			const ramNode& node = nodeArray.getNode(j);
			const string& name = node.getName();
			const ofVec3f &pos = node.getPosition();
			float qangle, qx, qy, qz;
			node.getOrientationQuat().getRotate(qangle, qx, qy, qz);
			
			frame
			<< name << "\t"
			<< ofToString(pos.x) << "\t"
			<< ofToString(pos.y) << "\t"
			<< ofToString(pos.z) << "\t"
			<< ofToString(qangle) << "\t"
			<< ofToString(qx) << "\t"
			<< ofToString(qy) << "\t"
			<< ofToString(qz) << "\t";
		}
		
		const float timestamp = nodeArray.getTimestamp();
		frame << ofToString(timestamp) << "\n";
		
		buf.append(frame.str().c_str(), frame.str().length());
	}
	
	const string fileName = mFileName.empty() ? timestampStr + "_" + entityName + ".tsv" : mFileName;

	const bool succeeded = ofBufferToFile(fileName, buf, true);
	
	if (succeeded)
	{
		cout << "[" << __FUNCTION__ << "] " << "Save succeeded! " << endl;
		cout << "[" << __FUNCTION__ << "] " << "File name:" << fileName << endl;
		cout << "[" << __FUNCTION__ << "] " << "Duration: " << src.getDuration() << "sec"<< endl;
		cout << "[" << __FUNCTION__ << "] " << "Frames: " << src.getNumFrames() << endl;
		cout << "[" << __FUNCTION__ << "] " << "Size: " << buf.size() * 0.001 << "KB" << endl << endl;
	}
	else
	{
		cout << "[" << __FUNCTION__ << "] " << "save failed.";
	}
	
	return succeeded;
}
예제 #30
0
파일: ofApp.cpp 프로젝트: 2bbb/ofxDatGui
void ofApp::onAddNewItemButtonClick(ofxDatGuiButtonEvent e)
{
    view->add("item " + ofToString(view->getNumItems() + 1));
    addItem->setLabel("click to add item - " + ofToString(view->getNumItems()) + " items");
}