Exemple #1
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    if(mode == 1) {
        ofPushMatrix();
//        ofTranslate(dx, dy);
//        ofScale(ofGetWidth()/kinect.width*dz,ofGetHeight()/kinect.height*dz);
//        input_image.draw(0,0);
        prettyContourFinder.draw(dx,dy, ofGetWidth()*dz, ofGetHeight()*dz);
//        input_image.draw(dx, dy, PROJECTOR_WIDTH*dz, PROJECTOR_HEIGHT*dz);
//        contourFinder.draw(dx, dy, ofGetWidth()*dz, ofGetHeight()*dz);
        ofPopMatrix();
    }
    else if (mode == 2) {
        ripples.draw(dx, dy, ofGetWidth()*dz, ofGetHeight()*dz);
//        input_image.draw(0, 0, ofGetWidth()*dz, ofGetHeight()*dz);
    }
    else if (mode == 3) {
        easyCam.begin();
        drawPointCloud();
        easyCam.end();
    }
    
    stringstream reportStream;
    reportStream << "Framerate: " << ofToString(ofGetFrameRate()) << endl
    << "Frame: " << ofToString(ofGetFrameNum()) << endl
    << "Threshold: " << threshold << endl
    << "Contour area: " << min_contour_area << endl
    << "Damping: " << ripples.damping << endl
    << "Tilt Angle: " << angle << endl
    << "RGB: " << red << ", " << green << ", " << blue << endl
//    << "Tempo: " << (1.0 / tempo) * 60 << "bpm" << endl;
    << (ofGetElapsedTimef() - lastBeat) / tempo << endl;
    if(display_feedback) {
        ofDrawBitmapString(reportStream.str(), 100, ofGetHeight() - 200);
    }
}
Exemple #2
0
void Windmill::update()
{
	angle += rotateSpeed;
	a = 80 * cos(ofGetFrameNum()/wavelength) + 80;
	
	pos += vel;
	
	if(pos.y > ofGetHeight()) {
		pos.y = ofGetHeight();
		vel.y *= -1;
	}
	if(pos.x > ofGetWidth()) {
		pos.x = ofGetWidth();
		vel.x *= -1;
	}
	if(pos.x < 0) {
		pos.x=0;
		vel.x *= -1;
	}
	if(pos.y < 0) {
		pos.y = 0;
		vel.y *= -1;
	}
}
Exemple #3
0
//--------------------------------------------------------------
void ofApp::update() {
	width = ofGetWidth(), height = ofGetHeight();
  t = ofGetFrameNum() * timeSpeed;
  for(int i = 0; i < nPoints; i++) {
		float x = points[i].x, y = points[i].y;
		ofVec2f field = getField(points[i]); // get the field at this position
		// use the strength of the field to determine a speed to move
		// the speed is changing over time and velocity-space as well
    float speed = (1 + ofNoise(t, field.x, field.y)) / pollenMass;
		// add the velocity of the particle to its position 
    x += ofLerp(-speed, speed, field.x);
    y += ofLerp(-speed, speed, field.y);
		// if we've moved outside of the screen, reinitialize randomly
    if(x < 0 || x > width || y < 0 || y > height) {
      x = ofRandom(0, width);
      y = ofRandom(0, height);
    }
		// save the changes we made to the position
    points[i].x = x;
    points[i].y = y;
		// add the current point to our collection of drawn points
		cloud.addVertex(ofVec2f(x, y));
	}
} 
//--------------------------------------------------------------
void ofApp::keyPressed(int key){

    if(key == 'm'){
        parameters.bMove = !parameters.bMove;
        
        if (parameters.bMove)
            paths.startDrawing();
        else
            paths.pauseDrawing();
    }
    
    if( key == 'r' ) {
        gizmo.setType( ofxGizmo::OFX_GIZMO_ROTATE );
    }
    if( key == 'g' ) {
        gizmo.setType( ofxGizmo::OFX_GIZMO_MOVE );
    }
    if( key == 's' ) {
        gizmo.setType( ofxGizmo::OFX_GIZMO_SCALE );
    }
    if( key == 'e' ) {
        gizmo.toggleVisible();
    }
    if(key == ' '){
        feedRate+=0.001;
        if(feedRate > 0.01){
            feedRate = 0.001;
        }
        line = buildPath();
        path.set(line);
        startFrameNum = ofGetFrameNum();
    }
    paths.keyPressed(key);

    handleViewportPresets(key);
}
Exemple #5
0
// add force and dye to fluid, and create particles
void testApp::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);
			
			fluidSolver.addColorAtIndex(index, drawColor * colorMult);
			
			if(drawParticles)
				particleSystem.addParticles(pos * ofVec2f(ofGetWindowSize()), 10);
		}
		
		if(addForce)
			fluidSolver.addForceAtIndex(index, vel * velocityMult);
		
    }
}
Exemple #6
0
void ofxSlider<Type>::draw(){
	ofPushStyle();
	ofPushMatrix();

	currentFrame = ofGetFrameNum();
	ofFill();
	ofSetColor(backgroundColor);
	ofRect(b);

	ofTranslate(b.x, b.y);
	float valAsPct = ofMap( value, min, max, 0, b.width-2, true );
	ofEnableAlphaBlending();
	ofSetColor(fillColor);
	ofRect(1, 1, valAsPct, b.height-2);

	ofTranslate(0, b.height / 2 + 4);
	ofSetColor(textColor);
	ofDrawBitmapString(name, textPadding, 0);
	string valStr = ofToString(value.getValue());
	ofDrawBitmapString(valStr, b.width - textPadding - valStr.length() * 8, 0);

	ofPopMatrix();
	ofPopStyle();
}
Exemple #7
0
//--------------------------------------------------------------
void testApp::keyPressed  (int key){ 
    switch(key) {
#ifdef USE_GUI
		case ' ':
			gui.toggleDraw();
			glClear(GL_COLOR_BUFFER_BIT);
			break;
#endif			
		case 'f':
			ofToggleFullscreen();
			break;
		case 's':
			static char fileNameStr[255];
			sprintf(fileNameStr, "output_%0.4i.png", ofGetFrameNum());
			static ofImage imgScreen;
			imgScreen.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
			printf("Saving file: %s\n", fileNameStr);
			imgScreen.saveImage(fileNameStr);
			break;
		case '1':
			videoSystem.vidGrabber.videoSettings();
			break;
	}
}
Exemple #8
0
void ofxGuiGroup::setValue(float mx, float my, bool bCheck){
    
	if( ofGetFrameNum() - currentFrame > 1 ){
		bGuiActive = false;
		return;
	}


	if( bCheck ){
		ofRectangle minButton(b.x+b.width-textPadding-10,b.y,10,header);
		if(minButton.inside(mx,my)){
			minimized = !minimized;
			if(minimized){
				minimize();
			}else{
				maximize();
			}
		}
		if( b.inside(mx, my) ){
			bGuiActive = true;
        }
	}

}
Exemple #9
0
//--------------------------------------------------------------
void testApp::update(){

    //Bonus stage material:
	// OSC receiver queues up new messages, so you need to iterate
	// through waiting messages to get each incoming message

	// check for waiting messages

	while( receiver.hasWaitingMessages() )
	{
		// get the next message
		ofxOscMessage m;
		receiver.getNextMessage( &m );
        ofLogVerbose("got a message");
		// check the address of the incoming message
		if ( m.getAddress() == "/chatlog" )
		{
			// get the first argument (we're only sending one) as a string
			if ( m.getNumArgs() > 0 ){
				if ( m.getArgType(0) == OFXOSC_TYPE_STRING){
					string oldMessages = messages;
					messages = m.getArgAsString(0) +"\n"+oldMessages;
				}
			}
		}
	}


    //this is purely workaround for a mysterious OSCpack bug on 64bit linux
    // after startup, reinit the receiver
    // must be a timing problem, though - in debug, stepping through, it works.
	if ( ofGetFrameNum() == 60 ){
        receiver.setup(recvPort);
	}

}
//--------------------------------------------------------------
void testApp::draw(){
	
    
    
    //----------------------------------- start draw for LEDS
    
    
    //    ofBackground( (int)( ofGetElapsedTimef() * 100 ) % 255);
    
    //    float sinOfTime = sin( ofGetElapsedTimef() * 10 );
    //    float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 0 ,30);
    //    ofSetColor( 127 + 127 * sin(ofGetElapsedTimef()));
    //    ofCircle(mouseX, ofGetHeight() * .5, sinOfTimeMapped * 10.0);
    
    
	// -------------------------- draw the line
	
    
    ofSetColor(fade);
    ofSetLineWidth(5);
    TPR.draw();
	
	// -------------------------- draw the point at the current time
	if (TPR.bHaveADrawing()){			// if we have a drawing to work with
		
		// figure out what time we are at, and make sure we playback cyclically (!)
		// use the duration here and make sure our timeToCheck is in the range of 0 - duration
		float timeToCheck = ofGetElapsedTimef() - playbackStartTime;
		while (timeToCheck > TPR.getDuration() && TPR.getDuration() > 0){
			timeToCheck -= TPR.getDuration();
		}
		
		// get the position and velocity at timeToCheck
		ofPoint pos = TPR.getPositionForTime(timeToCheck);
		ofPoint vel = TPR.getVelocityForTime(timeToCheck);
		
		// since velocity is a line, we want to know how long it is. 
		float lengthOfVel = ofDist(0,0,vel.x, vel.y);
		
		ofFill();
        float sinOfTime = sin( ofGetElapsedTimef() * 5 );
        float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 10 ,40);
        ofSetColor( 127 + 127 * sin(ofGetElapsedTimef()));
        //    ofCircle(mouseX, ofGetHeight() * .5, sinOfTimeMapped * 10.0);
		ofCircle(pos.x, pos.y, 2 + lengthOfVel/5.0);
		
		
	}
	
    
    
    
    //----------------------------------- end draw for LEDS
    
    
    ofImage imgTemp;
    imgTemp.grabScreen(0, ofGetHeight()/2, ofGetWidth(), 6);
    imgTemp.setImageType(OF_IMAGE_GRAYSCALE );
    
    imgTemp.resize(N_LIGHTS, 6);
    
    unsigned char * pixels = imgTemp.getPixels();
    
    
    
    
    
    if (ofGetFrameNum() % 3 == 0){
        serial.writeByte(255);
        for (int j = 0; j < N_LIGHTS; j++){
            float pct = ofMap(pixels[j], 0, 255, 0 , 1, true);
            float value = ofMap( powf(pct, 2), 0, 1, 0,253, true);
            serial.writeByte(value);
            
            //if (j %  (int)ofClamp(mouseX, 1, 10) == 0) serial.writeByte(254);
            //else serial.writeByte(0);
        }
    }
    
    ofSetColor(127);
    ofFill();
    ofRect(0, ofGetHeight()/2, ofGetWidth(), 6);
    
}
Exemple #11
0
//--------------------------------------------------------------
void HypercubeScene::update(){
    if (ofGetFrameNum() % 60 == 0){
        myShader.load("gradient");
    }

    
    if(numPoly < NUM_POLY){
        int newNumPoly = powf((ofGetElapsedTimef() - (float)resetMoment),2) * 2.0;
        if(newNumPoly > NUM_POLY)
            newNumPoly = NUM_POLY;
        
        if(numPoly != newNumPoly){
            for(int i = numPoly; i < newNumPoly; i++){
                brightnesses[i] = 1;
            }
            numPoly = newNumPoly;
        }
    }
    else
        numPoly = NUM_POLY;
    
    
    for(int i = 0; i < NUM_POLY; i++){
        brightnesses[i] *= 0.8;
    }

    
    float SCALE = .002;
    for(int i = 0; i < NUM_POLY; i++){
        polychron[i].rotate4DOnly(SCALE * sinf(ofGetElapsedTimef() * rotations[i].x),
                                  SCALE * sinf(ofGetElapsedTimef() * rotations[i].y),
                                  SCALE * sinf(ofGetElapsedTimef() * rotations[i].z) );
    }
    
    for(int i = 0; i < NUM_POLY; i++) {
        // CALCULATE the highlighted vertices
        highlighted[i].clear();
        for(int v = 0; v < polychron[i].getNumVertices(); v++){
            Point4D vertex = polychron[i].vertices[v];
            ofVec3f screenLocation = worldToScreen( ofVec3f(vertex.x, vertex.y, vertex.z), polyMatrix[i] );
            if(pointInHotspot(hotSpots[0], screenLocation) ||
               pointInHotspot(hotSpots[1], screenLocation) ||
               pointInHotspot(hotSpots[2], screenLocation)){
                highlighted[i].push_back(v);
                // vertex energy
                polychron[i].vertexEnergy[v] += 0.05;
                if(polychron[i].vertexEnergy[ v ] > 1)
                    polychron[i].vertexEnergy[ v ] = 1;
                // edge energy
                vector<unsigned int> adjEdg = polychron[i].allEdgesAdjacentTo(v);
                for(int q = 0; q < adjEdg.size(); q++){
                    polychron[i].edgeEnergy[ adjEdg[q] ] += .05;
                    if(polychron[i].edgeEnergy[ adjEdg[q] ] > 1)
                        polychron[i].edgeEnergy[ adjEdg[q] ] = 1;
                }
            }
        }
    }
        
    lastFaceNose = faceNose;
    
    float closeness = 100;
    float xRot = faceCenterSmooth.x * .5;
    float yRot = faceCenterSmooth.y * .5;

    headTiltMatrix.makeIdentityMatrix();
    headTiltMatrix.rotate(xRot, 0, 1, 0);
    headTiltMatrix.rotate(-yRot, 1, 0, 0);
    headTiltMatrix.translate(0, 0, closeness);

}
Exemple #12
0
void testApp::update() {
    //mCurrentTime = mTime->getTimeSecs();
    if(bSetup){
        cameraOne->update();
        if(mNumCameras == 0){
            mNumCameras = cameraOne->numCameras();
            mCameraMap = cameraOne->getSerialMap();
            mCaptureSize.set((ofGetWidth())/mNumCameras, 0);
            gui->addSpacer(255-2*OFX_UI_GLOBAL_WIDGET_SPACING, 2);
            gui->addWidgetDown(new ofxUILabel("CAMERAS", OFX_UI_FONT_MEDIUM));
            for(map<int, string>::iterator itr = mCameraMap.begin(); itr!=mCameraMap.end(); ++itr){
                CameraMapping[itr->second] = "";
                
                gui->addWidgetDown(new ofxUIButton("Cameria:"+ofToString(itr->first)+" serial: "+itr->second, false, 16, 16));
                //gui->addWidget(new ofxUITextInput(itr->second, ofToString(itr->first), OFX_UI_FONT_MEDIUM));
            }
            gui->autoSizeToFitWidgets();
        }
        if(cameraOne->isPhotoNew()) {
            mNewPhoto = true;
            map<string, ofBuffer> images = cameraOne->getImages();
            string dir = ofGetTimestampString();
            ofDirectory::createDirectory(ofGetTimestampString(), true);
            for(map<string, ofBuffer>::iterator itr = images.begin(); itr!=images.end(); ++itr){
                string filename = itr->first;
                if(itr->first == "292074032994"){
                    filename = "1";
                }else if(itr->first == "292074032993"){
                    filename = "2";
                }
                else if(itr->first == "292074032992"){
                    filename = "3";
                }
                
                else if(itr->first == "292074032989"){
                    filename = "4";
                }
                
                else if(itr->first == "342074067873"){
                    filename = "5";
                }
                
                else if(itr->first == "292074036327"){
                    filename = "6";
                }
                
                else if(itr->first == "342074067877"){
                    filename = "7";
                }
                
                else if(itr->first == "292074032991"){
                    filename = "8";
                }
                
                else if(itr->first == "322074063646"){
                    filename = "9";
                }
                
                else if(itr->first == "322074067491"){
                    filename = "10";
                }
                
                else if(itr->first == "322074062352"){
                    filename = "11";
                }
                
                else if(itr->first == "322074067417"){
                    filename = "12";
                }
                
                ofBufferToFile(dir+"/"+filename+".png", itr->second, true);
                ofImage foo;
                foo.loadImage(itr->second);
                captures.push_back(foo);
            }
        }else{
            mNewPhoto = false;
        }
        if(captures.size() > mNumCameras){
            captures.pop_front();
        }
        if(captures.size() > 0 && ofGetFrameNum()%16==0){
            mCurrentIndex++;
            if(mCurrentIndex>=mNumCameras){
                mCurrentIndex = 0;
            }
        }
    }
}
void testApp::drawPointCloud()
{
	int w = 640;
	int h = 480;
	    /* 
     Change the color based on time. You can use ofGetElapsedTimef() which returns
     a float for how many seconds this app has been running
     
     in can be used such as :
        sin( ofGetElapsedTimef() )
        ofNoise( ofGetElapsedTimef() )
     
     for interesting repeating animation patterns
     
     ofColor has a function called "fromHSB( hue , saturation , brightness )" that allows for easy color offset
     */
    
    //ofColor offset = ?
    ofPushMatrix();
    glEnable(GL_DEPTH_TEST);
    ofScale(1, -1, -1);
    ofTranslate(0, 0, -1000); // center the points a bit
    ofEnableBlendMode( OF_BLENDMODE_ALPHA ) ;

   

    ofColor offset = ofColor::fromHsb((ofGetFrameNum()/2  )%255, 255, 255 ) ;
   // ofEnableBlendMode( OF_BLENDMODE_ADD ) ;
	int step = 5 ;
    float boxSize = step ;//16.5f ;
	for(int y = 0; y < h; y += step) {
		for(int x = 0; x < w; x += step) {
			if(kinect.getDistanceAt(x, y) > 0) {
				
                ofVec3f vertex = kinect.getWorldCoordinateAt(x, y) ;
                if ( vertex.z > pointCloudMinZ && vertex.z < pointCloudMaxZ )
                {
                    float normalizedZ = ofMap( vertex.z , pointCloudMinZ , pointCloudMaxZ , -360.0f , 360.0f ) ; 
                    //mesh.addVertex( vertex );
                    
                    //Offset the color here
                    ofColor col = kinect.getColorAt(x,y) + offset ; // + offset ;
                    
                    //mesh.addColor( col );
                    ofSetColor( col ) ;
                    ofPushMatrix() ;
                        ofQuaternion rot ;
                        ofQuaternion rotX = ofQuaternion( sin( ofGetElapsedTimef() + y + x * 2.5f ) * 360.0f , ofVec3f( 0.0f , 1.0f , 0.0f ) ) ;
                        ofQuaternion rotY = ofQuaternion( normalizedZ , ofVec3f( 1.0f , 0.0f , 0.0f ) ) ;
                        rot = rotX * rotY ;
                        ofVec3f axis ;
                        float angle ;
                        rot.getRotate( angle , axis ) ;
                                          
                        ofTranslate( vertex ) ; 
                        ofRotate( angle , axis.x , axis.y , axis.z ) ;
                        ofBox( ofVec3f( )  , boxSize ) ;
                    ofPopMatrix() ;
                }
				
			}
		}
	}
    glDisable(GL_DEPTH_TEST);
    ofPopMatrix();
    ofEnableBlendMode( OF_BLENDMODE_ADD ) ; 
	//glPointSize(3);
	        // the projected points are 'upside down' and 'backwards' 
       
        
            //mesh.drawVertices();
    
       	
     
}
Exemple #14
0
//--------------------------------------------------------------
void ofApp::update(){
	
	// the background of the window is automatically cleared to the background color every frame.
	
	// BEGIN FBO
	nonFloatingPointFbo_GL_RGB.begin();
	// we draw a blue rectangle with an alpha value of 5 into the fbo
	// the higher the alpha value, the sooner the white line disappears
	
	ofSetColor(0, 0 , 255, 5);
    ofRect(0,0,400,200); // the rectangle covers the whole area of the fbo with the size of 400 by 200
	
	// we draw a line that moves from the left to the right inside the fbo:
	ofSetColor(0,0,0);
	// ofGetFrameNum() counts up in integer numbers and with modulus % we always get numbers that count from 0 to 400
	// so that the x position of the line moves constantly from 0 to 400
	ofLine(ofGetFrameNum()% 401 , 0, ofGetFrameNum()% 401, 200);
	
	
	// what happens inside the fbo here ?:
	
	// the black line that is drawn first on the very left side of the fbo gets more and more blue 
	// and it also gets more and more transparent over time.
	// the color changes from 0,0,0 to 0,0,255 
	// and the alpha value changes from 255 (fully visible) to 5 (very transparent).
	// after enough frames the black line which was drawn first on the very left with an alpha of 255 becomes blue with an alpha of 5
	// when the fbo is drawn onto a white background, the parts that are transparent appear to be more white
	
	// oldColor: black, alpha 255, newColor: blue, alpha 5
	// each frame the color gets more blue: oldColor * (255 - alpha) + (newColor * alpha)
	
	
    nonFloatingPointFbo_GL_RGB.end();
    // END FBO
	
	
	
	// we draw exactly the same ractangle and the same moving line into the other three fbos 
	
	
	// BEGIN FBO
    nonFloatingPointFbo_GL_RGBA.begin();
	
	ofSetColor(0, 0 , 255, 5);
    ofRect(0,0,400,200);
	
	ofSetColor(0,0,0);
	ofLine(ofGetFrameNum()% 401 , 0, ofGetFrameNum()% 401, 200);
	
	// what happens to the color in the non floating point fbo with GL_RGBA (with alpha):
	// the line is drawn with the color black, with an alpha value of 255			-> 0, 0, 0, 255
	// the blue rectangle is drawn with the color blue with an alpha value of 5		-> 0, 0, 255, 5
	// the color on the very left side of the fbo gets more blue and more transparent over time, 
	// but because of a rounding error, it does not reach the same numbers (in color and alpha) as in the floating point fbo.
    
    nonFloatingPointFbo_GL_RGBA.end();
	// END FBO
	
	
	// BEGIN FBO
	floatingPointFbo_GL_RGB32F_ARB.begin();
	
	ofSetColor(0, 0 , 255, 5);
    ofRect(0,0,400,200);
	
	ofSetColor(0,0,0);
	ofLine(ofGetFrameNum()% 401 , 0, ofGetFrameNum()% 401, 200);
	
    floatingPointFbo_GL_RGB32F_ARB.end();
	// END FBO
	
	
	// BEGIN FBO
	floatingPointFbo_GL_RGBA32F_ARB.begin();
	
	ofSetColor(0, 0 , 255, 5);
    ofRect(0,0,400,200);
	
	ofSetColor(0,0,0);
	ofLine(ofGetFrameNum()% 401 , 0, ofGetFrameNum()% 401, 200);
	
    floatingPointFbo_GL_RGBA32F_ARB.end();
	// END FBO
	
	
}
Exemple #15
0
//--------------------------------------------------------------
void RuleTen::draw(){
    //BG------white paper with light blue gridded lines--------------------
    ofBackground(255);
    ofSetColor( ofColor::lightBlue);
    ofSetLineWidth(1);
    for (int i = 0; i < ofGetWidth(); i = i + 20){
        ofLine(i,0,i, ofGetHeight());
        
    }
    
    for (int i = 0; i < ofGetHeight(); i = i + 20){
        ofLine(0, i, ofGetWidth(), i);
    }
    
    //------------------- start drawing ------------------------------------
  
    ofNoFill();
    int width;
    float resolution = 1000;
    ofPushMatrix();
     ofTranslate(570,450);
  
    
    for (int j = 0; j < 8; j++) {
    
        
        ofBeginShape();
         ofSetColor(colors[j]);
        ofSetLineWidth(LineWeight[j]);
        
       
        for(int i=0; i<=resolution; i++) {
            
            float t = i/resolution;
            
            float xraw = sin(t*TWO_PI);
            float yraw = cos(t*TWO_PI);
            
            float displaceNoiseMod = ofNoise(xraw+ofGetElapsedTimef(), yraw+ofGetElapsedTimef()) * radius[j];
            displaceNoiseMod*=noiseModFactor[j].get();
            
            float wave = (displaceNoiseMod+radius[j]) * amplitude[j] * sin(t*TWO_PI*peaks[j] + ofGetFrameNum()*velocity[j])  ;
    
            float x = (radius[j]+wave) * xraw;
            float y = (radius[j]+wave) * yraw;
            
            ofCurveVertex(x, y);
          
        
        }
         ofEndShape();
    }
    
        ofPopMatrix();

        for (int i = 0; i < 8; i++){
            panels[i].draw();
        }
    ofPushMatrix();
    ofRotate(-9);
    ofSetColor(73,66,54); //brown
    Break.draw(10,90,700/1.2,181/1.2);
    ofPopMatrix();
    YouCan.draw(1000, 745, 289,103);
    
    ofSetColor(255);
    Nav.draw(0,0,ofGetWidth(),ofGetHeight());
    
}
Exemple #16
0
//--------------------------------------------------------------
void testApp::update(){
    if (ofGetFrameNum() == 2) GUI.show();
}
void ofxClickDownMenu::draw(){
	ofEnableBlendMode(OF_BLENDMODE_ALPHA);
	if (phase == PHASE_CLICK){
		frame += 1 * 90.0f / ofGetFrameRate();
		window_y += (window_size.y - window_y) / 5.0 * 120.0f / ofGetFrameRate();
		window_y = MIN(window_size.y,window_y);
		ofSetColor(255, 255, 255,140);
		ofNoFill();
		ofRect(window_pos,window_size.x,window_y);
		ofFill();
		ofSetColor(0, 0, 0,100);
		ofRect(window_pos,window_size.x,window_y);
		
		for (int i = 0;i < menus.size();i++){
			if (frame > i*3) {
				ofSetColor(255,255,255,100);
				if (i > 0) ofLine(window_pos.x		, window_pos.y+i*20, 
								  window_pos.x+window_size.x*(1-(powf((MIN(1.0,MAX(0.0,frame-i*3)/15.0))-1.0,4.0))),
								  window_pos.y+i*20);
				ofSetColor(255,255,255);
				string mes = "";
				
				mes += menus[i].message.substr(0,MIN(menus[i].message.length(),(frame-i*3)/2));
				
				for (int j = 0;j < MAX(0,(float)menus[i].message.length()-MAX(0,(frame-i*3)/2));j++){
					mes += ofToString((char)ofRandom(33,120));
				}
				if (menus[i].isBranch) mes += " >";
				if (useFont){
					font.drawString(mes, window_pos.x+4,window_pos.y+i*20+15);					
				}else{
					ofDrawBitmapString(mes, window_pos.x+4,window_pos.y+i*20+13);					
				}
			}
			if (menu_focused == i){
				ofEnableBlendMode(OF_BLENDMODE_ADD);
				ofSetColor(hilight);
//				ofRect(window_pos.x,window_pos.y+i*20, window_size.x, 20);
				ofEnableBlendMode(OF_BLENDMODE_ALPHA);
			}
		}
		ofSetColor(hilight);
		focus_y += (menu_focused*20 - focus_y) / 2.0;
		focus_y = MAX(0,focus_y);
		ofEnableBlendMode(OF_BLENDMODE_ADD);
		ofRect(window_pos.x, window_pos.y+focus_y, window_size.x, 20);
		ofEnableBlendMode(OF_BLENDMODE_ALPHA);
	}
	if (phase == PHASE_SELECT){
		frame += 1 * 90.0f / ofGetFrameRate();;
		ofSetHexColor(0xFFFFFF);
		if (frame > 7) ofSetColor(255*(ofGetFrameNum()%2));
		if (useFont){
			font.drawString(menus[menu_focused].message, window_pos.x+4,window_pos.y+menu_focused*20+15);				
		}else{
			ofDrawBitmapString(menus[menu_focused].message, window_pos.x+4,window_pos.y+menu_focused*20+13);	
		}
		
		ofEnableBlendMode(OF_BLENDMODE_ADD);
		if (frame > 7) ofSetColor(hilight.r,hilight.g,hilight.b,255*ofGetFrameNum()%2);
		else		   ofSetColor(hilight);

		hl.a -= 20;
		ofSetColor(hl);
		ofNoFill();

		ofRect(window_pos.x,window_pos.y+menu_focused*20+10, window_size.x, 5.0/(frame));
		ofRect(window_pos.x, window_pos.y, window_size.x, window_size.y);
		ofFill();
		if (frame > 15){
			if (isChild){
				parent->haveChild = false;
				delete this;
			}
			phase = PHASE_WAIT;
		}
	}				
	
	if (haveChild) child->draw();
	if (haveFChild)fchild->draw();
	ofEnableBlendMode(OF_BLENDMODE_ALPHA);
	ofSetRectMode(OF_RECTMODE_CORNER);
}
Exemple #18
0
//--------------------------------------------------------------
void ofApp::update(){
//    ofBackground(30);
    
    ofSoundUpdate();
    
    float _maxSpeed = 20;
    float _minSpeed = 150;
    
    bellFrameTempo = ofGetFrameNum() % bellTempoChange;
    if (bellFrameTempo == 0) {
        bellTriggerSignal = true;
        sequence.bellNoteMake(bellTriggerSignal);
        
        synth1.setParameter("trigger1", 1 );
        synth1.setParameter("carrierPitch1", sequence.bellPlayNote );
        
        belltweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[2],sequence.bellPointPos[1],bellTempoChange*33/10,0);
        belltweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[3],sequence.bellPointPos[2],bellTempoChange*33/8,0);
        belltweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[4],sequence.bellPointPos[3],bellTempoChange*33/6,0);
        belltweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[5],sequence.bellPointPos[4],bellTempoChange*33/4,0);
        belltweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[6],sequence.bellPointPos[5],bellTempoChange*33/4,0);
        
//        belltweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[2],sequence.bellPointPos[1],bellTempoChange*33/8,0);
//        belltweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[2],sequence.bellPointPos[1],bellTempoChange*33/6,0);
//        belltweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[2],sequence.bellPointPos[1],bellTempoChange*33/4,0);
//        belltweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[2],sequence.bellPointPos[1],bellTempoChange*33/2,0);
//        belltweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.bellPointPos[2],sequence.bellPointPos[1],bellTempoChange*33/1,0);
        
    } else if (bellFrameTempo == 1) {
        bellTriggerSignal = false;
        sequence.bellNoteMake(bellTriggerSignal);
        bellTempoChange = (int)ofRandom(_maxSpeed, _minSpeed); // Tempo Random change
    }
    else {
        bellTriggerSignal = false;
    }
    
    
    synthFrameTempo = ofGetFrameNum() % synthTempoChange;
    if (synthFrameTempo == 0) {
        synthTriggerSignal = true;
        sequence.synthNoteMake(synthTriggerSignal);

        synth2.setParameter("trigger2", 1 );
        synth2.setParameter("carrierPitch2", sequence.synthPlayNote );
        
        synthtweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[2],sequence.synthPointPos[1],synthTempoChange*33,0);
        synthtweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[3],sequence.synthPointPos[2],synthTempoChange*33,0);
        synthtweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[4],sequence.synthPointPos[3],synthTempoChange*33,0);
        synthtweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[5],sequence.synthPointPos[4],synthTempoChange*33,0);
        synthtweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[6],sequence.synthPointPos[5],synthTempoChange*33,0);

//        synthtweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[2],sequence.synthPointPos[1],synthTempoChange*33/8,0);
//        synthtweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[2],sequence.synthPointPos[1],synthTempoChange*33/6,0);
//        synthtweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[2],sequence.synthPointPos[1],synthTempoChange*33/4,0);
//        synthtweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[2],sequence.synthPointPos[1],synthTempoChange*33/2,0);
//        synthtweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.synthPointPos[2],sequence.synthPointPos[1],synthTempoChange*33/1,0);
    } else if (synthFrameTempo == 1) {
        synthTriggerSignal = false;
        sequence.synthNoteMake(synthTriggerSignal);
        synthTempoChange = (int)ofRandom(_maxSpeed, _minSpeed); // Tempo Random change
    }
    else {
        synthTriggerSignal = false;
    }

    
    
    bassFrameTempo = ofGetFrameNum() % bassTempoChange;
    if (bassFrameTempo == 0) {
        bassTriggerSignal = true;
        sequence.bassNoteMake(bassTriggerSignal);
        synth3.setParameter("trigger3", 1 );
        synth3.setParameter("carrierPitch3", sequence.bassPlayNote );

        basstweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[2],sequence.bassPointPos[1],bassTempoChange*33,0);
        basstweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[3],sequence.bassPointPos[2],bassTempoChange*33,0);
        basstweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[4],sequence.bassPointPos[3],bassTempoChange*33,0);
        basstweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[5],sequence.bassPointPos[4],bassTempoChange*33,0);
        basstweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[6],sequence.bassPointPos[5],bassTempoChange*33,0);
        
//        basstweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[2],sequence.bassPointPos[1],bassTempoChange*33/8,0);
//        basstweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[2],sequence.bassPointPos[1],bassTempoChange*33/6,0);
//        basstweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[2],sequence.bassPointPos[1],bassTempoChange*33/4,0);
//        basstweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[2],sequence.bassPointPos[1],bassTempoChange*33/2,0);
//        basstweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.bassPointPos[2],sequence.bassPointPos[1],bassTempoChange*30/1,0);
    } else if (bassFrameTempo == 1) {
        bassTriggerSignal = false;
        sequence.bassNoteMake(bassTriggerSignal);
        bassTempoChange = (int)ofRandom(_maxSpeed, _minSpeed); // Tempo Random change
    }
    else {
        bassTriggerSignal = false;
    }

    
    
    padFrameTempo = ofGetFrameNum() % padTempoChange;
    if (padFrameTempo == 0) {
        padTriggerSignal = true;
        sequence.padNoteMake(padTriggerSignal);
        synth4.setParameter("trigger4", 1 );
        synth4.setParameter("carrierPitch4", sequence.padPlayNote );

        padtweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[2],sequence.padPointPos[1],padTempoChange*33,0);
        padtweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[3],sequence.padPointPos[2],padTempoChange*33,0);
        padtweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[4],sequence.padPointPos[3],padTempoChange*33,0);
        padtweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[5],sequence.padPointPos[4],padTempoChange*33,0);
        padtweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[6],sequence.padPointPos[5],padTempoChange*33,0);
        
//        padtweenelastic1.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[2],sequence.padPointPos[1],padTempoChange*33/8,0);
//        padtweenelastic2.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[2],sequence.padPointPos[1],padTempoChange*33/6,0);
//        padtweenelastic3.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[2],sequence.padPointPos[1],padTempoChange*33/4,0);
//        padtweenelastic4.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[2],sequence.padPointPos[1],padTempoChange*33/2,0);
//        padtweenelastic5.setParameters(0,easingquad,ofxTween::easeOut,sequence.padPointPos[2],sequence.padPointPos[1],padTempoChange*33/1,0);
    } else if (padFrameTempo == 1) {
        padTriggerSignal = false;
        sequence.padNoteMake(padTriggerSignal);
        padTempoChange = (int)ofRandom(_maxSpeed, _minSpeed); // Tempo Random change
    }
    else {
        padTriggerSignal = false;
    }
    
    if ((PmouseXmoving - mouseXp)==0) {
        xRotateDir = 0;
    }
    if ((PmouseXmoving - mouseXp)>0) {
        xRotateDir = 2;
    } else if ((PmouseXmoving - mouseXp)<0) {
        xRotateDir = -2;
    }
    
    if ((PmouseYmoving - mouseYp)==0) {
        yRotateDir = 0;
    }
    if ((PmouseYmoving - mouseYp)>0) {
        yRotateDir = 2.2;
    } else if ((PmouseYmoving - mouseYp)<0) {
        yRotateDir = -2.2;
    }
    
    
    xRotate = xRotate + xRotateDir;
    yRotate = yRotate + yRotateDir;
    
    PmouseXmoving = mouseXp;
    PmouseYmoving = mouseYp;
    
    //    for(int i = 0; i<6; i++) {
    //        sizeIncreaseArr[i] = sizeIncreaseArr[i] + 1;
    //        if(sizeIncreaseArr[i] > 50) {
    //            sizeIncreaseArr[i] = 0;
    //        }
    //    }
    
    sizeIncreaseBell = sizeIncreaseBell + 1;
    if((sizeIncreaseBell > 220)||(bellTriggerSignal)) {
        sizeIncreaseBell = 20;
    }
    sizeIncreaseSynth = sizeIncreaseSynth + 1;
    if((sizeIncreaseSynth > 220)||(synthTriggerSignal)) {
        sizeIncreaseSynth = 20;
    }
    sizeIncreaseBass = sizeIncreaseBass + 1;
    if((sizeIncreaseBass > 220)||(bassTriggerSignal)) {
        sizeIncreaseBass = 20;
    }
    sizeIncreasePad = sizeIncreasePad + 1;
    if((sizeIncreasePad > 220)||(padTriggerSignal)) {
        sizeIncreasePad = 20;
    }
    
    alphaTBellcircle = alphaTBellcircle - 1;
    if ((bellTriggerSignal)) {
        alphaTBellcircle = 120;
    }
    alphaTSynthcircle = alphaTSynthcircle - 1;
    if ((synthTriggerSignal)) {
        alphaTSynthcircle = 120;
    }
    alphaTBasscircle = alphaTBasscircle - 1;
    if ((bassTriggerSignal)) {
        alphaTBasscircle = 120;
    }
    alphaTPadcircle = alphaTPadcircle - 1;
    if ((padTriggerSignal)) {
        alphaTPadcircle = 120;
    }
}
Exemple #19
0
void testApp::draw(){
ofSetColor(255, 255, 255);

    while(buffer.size() > maxBufferSize) {
        delete [] buffer.front();
        buffer.pop_front();
    }

    if(!buffer.empty()) {
        unsigned char* cur = buffer.front();
        int size = scanner.getBufferSize();
        float width = ofGetWidth();
        float height = ofGetHeight();

        // draw color components
        ofSetColor(255, 0, 0);
        drawRgbPlot(cur, size, 0, width, height);
        ofSetColor(0, 255, 0);
        drawRgbPlot(cur, size, 1, width, height);
        ofSetColor(0, 0, 255);
        drawRgbPlot(cur, size, 2, width, height);

        // draw buffer size
        ofSetColor(255, 255, 255);
        //ofLine(0, height / 2, ofMap(buffer.size(), 0, minBufferSize * 4, 0, width), height / 2);

        // average + normalize all channels
        if(lowPass == NULL) {
            white = new float[size / 3];
            lowPass = new float[size / 3];
        }
        for(int i = 0; i < size / 3; i++) {
            white[i] = cur[i * 3] + cur[i * 3 + 1] + cur[i * 3 + 2];
            white[i] /= 3. * 255.;
        }

        // low pass from left
        int lowPassSize = size / 3;
        float lowPassAmount = .005;
        float average;
        average = 1;
        for(int i = 0; i < lowPassSize; i++) {
            average = ofLerp(average, white[i], lowPassAmount);
            lowPass[i] = average;
        }
        // low pass from right
        average = 1;
        for(int i = lowPassSize - 1; i >= 0; i--) {
            average = ofLerp(average, white[i], lowPassAmount);
            lowPass[i] = (lowPass[i] + average) / 2;
        }

        // draw low passed data
        glBegin(GL_LINE_STRIP);
        for(int i = 0; i < lowPassSize; i++) {
            float x = ofMap(i, 0, lowPassSize, 0, width);
            float y = ofMap(lowPass[i], 0, 1, height, 0);
            glVertex2f(x, y);
        }
        glEnd();

        // draw local minima
        int dist = 128;
        for(int i = dist; i < lowPassSize - dist; i++) {
            if(significantMinima(lowPass[i - dist], lowPass[i], lowPass[i + dist], .001)) {
                float x = ofMap(i, 0, lowPassSize, 0, width);
                float y = ofMap(lowPass[i], 0, 1, height, 0);
                ofLine(x, y, x, height);
            }
        }

        delete [] buffer.front();
        buffer.pop_front();
    }

    if(ofGetFrameNum() % 60 == 0 && ofGetFrameRate() < 60)
        cout << "slow: " << ofGetFrameRate() << "fps" << endl;
}
Exemple #20
0
//---------------------------------------------------------------------------------
void ofxLogger::_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 the message
	//
	// Each log call is wrapped in a try / catch in case the logger is called
	// when it has already been destroyed. This can happen if it is used in
	// another destructor as the destruction order is not predictabale.
	//
	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_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;
	}
}
Exemple #21
0
void Renderer::draw()
{
	ofBackground(0);

	ofPushMatrix();

		// afficher un repère visuel pour les lumières
		if(isActiveLightPoint)
			lightPoint->draw();
		if(isActiveLightDirectional)
			lightDirectional->draw();
		if(isActiveLightSpot)
			lightSpot->draw();

	ofPopMatrix();

	ofPushMatrix();

		// inverser l'axe Y pour qu'il pointe vers le haut
		ofScale(1, isFlipAxisY ? -1 : 1);

		// transformer l'origine de la scène au milieu de la fenêtre d'affichage
		ofTranslate(xCenter + xOffset, isFlipAxisY ? -yCenter : yCenter, zOffset);

		// légère rotation de la scène
		ofRotate(ofGetFrameNum() * 0.25f, 0, 1, 0);

		ofPushMatrix();

			// position
			ofTranslate(
				positionCube->x,
				positionCube->y,
				positionCube->z);

			// rotation locale
			ofRotate(ofGetFrameNum() * 1.0f, 0, 1, 0);

			// activer l'éclairage dynamique
			ofEnableLighting();

			// activer les lumières
			lightingOn();

			// activer le matériau
			materialCube->begin();

			// dessiner un cube
			ofDrawBox(0, 0, 0, scaleCube);

			// désactiver le matériau
			materialCube->end();

			// désactiver les lumières
			lightingOff();

			// désactiver l'éclairage dynamique
			ofDisableLighting();

		ofPopMatrix();

		ofPushMatrix();

			// position
			ofTranslate(
				positionSphere->x,
				positionSphere->y,
				positionSphere->z);

			// rotation locale
			ofRotate(ofGetFrameNum() * 1.0f, 0, 1, 0);

			// activer l'éclairage dynamique
			ofEnableLighting();

			// activer les lumières
			lightingOn();

			// activer le matériau
			materialSphere->begin();

			// dessiner une sphère
			ofDrawSphere(0, 0, 0, scaleSphere);

			// désactiver le matériau
			materialSphere->end();

			// désactiver les lumières
			lightingOff();

			// désactiver l'éclairage dynamique
			ofDisableLighting();

		ofPopMatrix();

		ofPushMatrix();

			// position
			teapot->setPosition(
				positionTeapot->x,
				positionTeapot->y + 15,
				positionTeapot->z);

			// rotation locale
			teapot->setRotation(0, ofGetFrameNum() * -1.0f, 0, 1, 0);

			// dimension
			teapot->setScale(
				scaleTeapot,
				scaleTeapot,
				scaleTeapot);

			// activer l'éclairage dynamique
			ofEnableLighting();

			// activer les lumières
			lightingOn();

			// activer le matériau
			materialTeapot->begin();

			// dessiner un teapot
			teapot->draw(OF_MESH_FILL);

			// désactiver le matériau
			materialTeapot->end();

			// désactiver les lumières
			lightingOff();

			// désactiver l'éclairage dynamique
			ofDisableLighting();

		ofPopMatrix();

	ofPopMatrix();
}
void ofApp::update(){
    manager.update();
    
    val = ofMap(cos(ofGetFrameNum() * 0.04), -1, 1, 0, 1);
    chains.at(0).getSynth()->set(TALNoiseMaker_osc1tune, val);
}
void zoneManager::update(map<string, ofPtr<clamourNode> > tNodes) {

    appReactions.clear();

    //implement scheduled commands
    vector<eventComm>::iterator e_it = mFutureEvents.begin();

    while(e_it != mFutureEvents.end()) {
        if(e_it->execAt == ofGetFrameNum()) {
            if(mZones.find(e_it->ownerIndex) != mZones.end()){
                implementReaction(e_it->r, mZones[e_it->ownerIndex]);
            }
            e_it = mFutureEvents.erase(e_it);
        } else {
            ++e_it;
        }
    }

    map<string, ofPtr<zone> >::iterator z_it;
    map<string, ofPtr<clamourNode> >::iterator n_it;

    //call update method here which resets closed zones and increments reactions etc

    for(z_it = mZones.begin(); z_it != mZones.end(); ++z_it) {
        z_it->second->update();
        z_it->second->updateEvents();
        z_it->second->updateDrawData();
        if(getOffTrig(z_it->second)) {
            offReact(z_it->second);
        }

    }



    //find node intersections
    n_it = tNodes.begin();

    while(n_it != tNodes.end()) {

        if(n_it->second->getIsSleeping()) {

            if(n_it->second->getZonePair()) {
                if(!n_it->second->getZonePair()->getIsClosedIn()) {
                    n_it->second->getZonePair()->removeNode(n_it->second);
                    n_it->second->resetZonePair();
                }
            }

            ++n_it;
            continue;

        }


        for(z_it = mZones.begin(); z_it != mZones.end(); ++z_it) {

            if(z_it->second->getIsClosedIn()) {

                if(n_it->second->getZonePair() == z_it->second) {
                    //only for already captured nodes
                    containNode(n_it->second, z_it->second);
                    continue; // mustn't allow other reactions

                }

            }

            if(checkInZone(n_it->second, z_it->second)) {


                if(n_it->second->getZonePair() == z_it->second) {
                    break; //already in the zone
                }

                //new nodes inside the zone

                if(z_it->second->getIsClosedOut()) {
//                    cout << "repell \n";
                    repellNode(n_it->second, z_it->second);
                } else {


                    if(n_it->second->getZonePair()) {
                        //incase the node has jumped straight from one zone to the next
                        n_it->second->getZonePair()->removeNode(n_it->second);
                        n_it->second->resetZonePair();
                    }

                    n_it->second->setZonePair(z_it->second);
                    z_it->second->addNode(n_it->second);

                    //now update zone reactions
                    if(getOnTrig(z_it->second))onReact(z_it->second);

                    break; //no need to check any more zones for this node
                }

            } else if(n_it->second->getZonePair() == z_it->second) {
                z_it->second->removeNode(n_it->second);
                n_it->second->resetZonePair();
            }

        }

        ++n_it;
    }




}
//--------------------------------------------------------------
void testApp::draw(){
	
        
    
    //----------------------------------- start draw for LEDS
    
    
//    ofBackground( (int)( ofGetElapsedTimef() * 100 ) % 255);
//        
//    float sinOfTime = sin( ofGetElapsedTimef() * 10 );
//    float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 0 ,30);
//    ofSetColor( 127 + 127 * sin(ofGetElapsedTimef()));
//    ofCircle(mouseX, ofGetHeight() * .5, sinOfTimeMapped * 10.0);
    
    
    
    
    //----------------mi creature
    
    
    ofEnableAlphaBlending();  //para cambiar la transparencia
    ofSetColor(255,255,255);
    
    stroke.draw();
    
    ofMesh mesh;
    mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
    
    
    
    
    vector < ofPoint > pts = stroke.getVertices();
    
    for (int i = 0; i < pts.size(); i++){
        
        int i_m_1 = MAX(i-1,0);
        int i_p_1 = MIN(i+1, pts.size()-1);
        
        ofPoint pta = pts[i_m_1];
        ofPoint ptb = pts[i];
        ofPoint ptc = pts[i_p_1];
        
        ofPoint diff = ptc - pta;
        
        float angle = atan2(diff.y, diff.x);
        
        angle += PI/2;
        
        float width = 20; //diff.length();
        
        ofPoint offsetA;
        offsetA.x = ptb.x + width * cos(angle);
        offsetA.y = ptb.y + width * sin(angle);
        
        ofPoint offsetB;
        offsetB.x = ptb.x - width * cos(angle);
        offsetB.y = ptb.y - width * sin(angle);
        
        ofLine(offsetA, offsetB);
        
        ofCircle(offsetA, 1.7);
        ofCircle(offsetB, 1.7);
        
        
        mesh.addVertex(offsetA); // le dibuja un lado de la cuncuna
        
        mesh.addVertex(offsetB); // dibuja el otro lado de la cuncuna
        
        if (onoff == false){
            
            float sinOfTime = sin( ofGetElapsedTimef() * (0.7)); //for the speed of on/off
            float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 0, 255);
            
            
            ofSetColor(255,255,255,sinOfTimeMapped);
            ofFill();
            ofCircle(ptc.x, ptc.y, 4);
            mesh.draw();
            ofLine(offsetA, offsetB);
            
            
            /// ---- > lines.push_back(stroke);
            
            
        }
        
        
        if (onoff == true){
            
          
            ofSetColor(255, 255, 255);
            ofFill();
            ofCircle( mouseX, mouseY, 4);
            
        }
    }
    
    
    
    for (int i = 0; i < lines.size(); i++){
        mesh.clear();
        vector < ofPoint > pts = lines[i].getVertices();
        for (int j = 0; j < pts.size(); j++){
            
            int j_m_1 = MAX(j-1,0);
            int j_p_1 = MIN(j+1, pts.size()-1);
            
            ofPoint pta = pts[j_m_1];
            ofPoint ptb = pts[j];
            ofPoint ptc = pts[j_p_1];
            
            ofPoint diff = ptc - pta;
            
            float angle = atan2(diff.y, diff.x);
            
            angle += PI/2;
            
            float width = 20; //diff.length();
            
            ofPoint offsetA;
            offsetA.x = ptb.x + width * cos(angle);
            offsetA.y = ptb.y + width * sin(angle);
            
            ofPoint offsetB;
            offsetB.x = ptb.x - width * cos(angle);
            offsetB.y = ptb.y - width * sin(angle);
            
            ofLine(offsetA, offsetB);
            
            ofCircle(offsetA, 1.7);
            ofCircle(offsetB, 1.7);
            
            
            mesh.addVertex(offsetA); // le dibuja un lado de la cuncuna
            
            mesh.addVertex(offsetB); // dibuja el otro lado de la cuncuna
            
            if (true){
                
                float sinOfTime = sin( ofGetElapsedTimef() * (0.7) + i * 0.3); //for the speed of on/off
                float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 0, 255);
                
                
                ofSetColor(255,255,255,sinOfTimeMapped);
                ofFill();
                ofCircle(ptc.x, ptc.y, 4);
                mesh.draw();
                ofLine(offsetA, offsetB);
                
         
                
                
            }
            
          
        }
    }
    


    
    
    //----------------------------------- end draw for LEDS
    
    
    ofImage imgTemp;
    imgTemp.grabScreen(0, ofGetHeight()/2, ofGetWidth(), 2);
    imgTemp.setImageType(OF_IMAGE_GRAYSCALE );
    
    imgTemp.resize(N_LIGHTS, 2);
    
    unsigned char * pixels = imgTemp.getPixels();
    
    
    
    
        
        if (ofGetFrameNum() % 3 == 0){
            serial.writeByte(255);
            for (int j = 0; j < N_LIGHTS; j++){
                
                float pct = ofMap(pixels[j], 0, 255, 0 , 1, true);
                
                
                float value = ofMap( powf(pct, 2), 0, 1, 0,253, true);
                serial.writeByte(value);
                //if (j %  (int)ofClamp(mouseX, 1, 10) == 0) serial.writeByte(254);
                //else serial.writeByte(0);
                                
            
            }
        }

ofSetColor(255);
    ofRect(0, ofGetHeight()/2, ofGetWidth(), 2);


}
Exemple #25
0
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button)
{
    path->lineTo(x,y,0, ofFloatColor(0), ofGetFrameNum(), 0);
}
Exemple #26
0
void testApp::houghCircles( ofxCvGrayscaleImage sourceImg) {
	IplImage* gray = sourceImg.getCvImage();	
	cvSmooth( gray, gray, CV_GAUSSIAN, 5, 5 ); // smooth it, otherwise a lot of false circles may be detected
	CvMemStorage* storage = cvCreateMemStorage(0);	
	circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 2, gray->width/8, 300, 200 );
	circCount = circles->total;
    
	// find positions of CV circles
	
	for (int i = 0; i < circles->total; i++) 
	{
		float* p = (float*)cvGetSeqElem( circles, i );
		ofPoint pos;
		pos.x = cvPoint( cvRound(p[0]),cvRound(p[1]) ).x;  
		pos.y = cvPoint( cvRound(p[0]),cvRound(p[1]) ).y;
		pos.x = (int)pos.x;
		pos.y = (int)pos.y;
		int radius = cvRound( p[2] );
		
		bool cFound = false;
		
		for (int circs = 0; circs < myCircles.size(); circs++) 
		{
			ofPoint& posCirc = myCircles[circs].pos;
			float dist = ofDistSquared(pos.x, pos.y, posCirc.x, posCirc.y);
			//cout << "distance is: " << dist << endl;
			
			// check to see if there is a circle near an existing tracked circle
			if ( dist < 1000 ) 
			{
				myCircles[circs].lastSeen = ofGetFrameNum();
				myCircles[circs].radius = radius;
				myCircles[circs].pos = pos;
				myCircles[circs].isAlive += 1;
				cFound = true;
			}
		}
		
		if (!cFound) 
		{
            radius *=1.05;
			CircleTrack c = CircleTrack( pos );
			c.pos = pos;
			c.radius = radius;
			c.lastSeen = ofGetFrameNum();
			c.isAlive = 0;
			c.drawMe = false;
			c.isSetUp = false;
			c.iD = circID;
			
			if (c.radius) {
				myCircles.push_back(c);
				circID++;
                
                ofPixels pixCopy = pix;
                pixCopy.crop( pos.x-radius, (pos.y-radius), radius*2 , radius*2 );
                tex.loadData( pixCopy );
                
                ofTexture T;
                T.allocate(radius*2,radius*2, GL_RGB);
                T.loadData(pixCopy);
                particle P = particle( pos,circID,radius,T  );
                punched.push_back( P );
                printf("punched %f,%f\n", pos.x,pos.y);
                
			}
		}
	}	
	
	cvReleaseMemStorage(&storage);
	
	for ( int x = 0; x<myCircles.size(); x++ ) 
    {
		bool isSetupNow = myCircles[x].isSetUp;
		if ( !isSetupNow ) {
			myCircles[x].setup();
		}
	}
	

	vector<CircleTrack>::iterator iter = myCircles.begin();
	while (iter != myCircles.end()) {
		
		double life = iter->lastSeen;
		int isAlive = iter->isAlive;
    
        // kill old particles;
        
		if ( (ofGetFrameNum()-life) > 50 ) 
        {
			
			ofPoint tracePos = iter->pos;
			iter = myCircles.erase(iter);
			cout << "shape deleted at: "<< tracePos.x << ", " << tracePos.y << endl;
			
			
		} else {
			
			if (iter->isAlive > 0) // used to be 3? 
            {
				iter->drawMe = true;
			} else 
            {
				iter->drawMe = false;
			}
			iter++;
		}
	}
}
Exemple #27
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){

	if(key=='s'){
		string fn = ofToString(mc.gx) +"x"+ofToString(mc.gy)+"x"+ofToString(mc.gz)+"-"+ofToString(ofGetFrameNum())+".stl";
		mc.saveStl(fn);
	}
	if(key=='c'){
		mc.clear();
		mc.polygoniseData();
	}
	if(key=='f'){
		mc.multData(0.9f);
		mc.polygoniseData();
	}
}
//--------------------------------------------------------------
void testApp::draw() {
    
    // we need some images if not return
    // 如果没有加载任何图片,我们会被告知
    if((int)images.size() <= 0) {
        ofSetColor(255);
        ofDrawBitmapString("No Images...", 150, ofGetHeight()/2);
        return;
    }
    
    // this is the total time of the animation based on fps
    // 下面是计算播放动画所需时间的公式
    //float totalTime = images.size() / sequenceFPS;
    
    
    
    int frameIndex = 0;
    
    if(bFrameIndependent) {
        // calculate the frame index based on the app time
        // and the desired sequence fps. then mod to wrap
        
        //计算时间和帧速率,得出这一帧需要播放的内容
        frameIndex = (int)(ofGetElapsedTimef() * sequenceFPS) % images.size();
    }
    else {
        // set the frame index based on the app frame
        // count. then mod to wrap.
        //计算应用的总帧数,得出这一帧需要播放的内容
        frameIndex = ofGetFrameNum() % images.size();
    }
    
    // draw the image sequence at the new frame count
    // 画出图片序列
    ofSetColor(255);
    images[frameIndex].draw(256, 36);
    
    
    // draw where we are in the sequence
    // 画出图片序列的缩略图
    float x = 0;
    for(int offset = 0; offset < 5; offset++) {
			int i = (frameIndex + offset) % images.size();
        ofSetColor(255);
        images[i].draw(200+x, ofGetHeight()-40, 40, 40);
        x += 40;
    }
    
    
    // how fast is the app running and some other info
    // 应用的一些信息,如应用的运行速度等
    ofSetColor(50);
    ofRect(0, 0, 200, 200);
    ofSetColor(200);
    string info;
    info += ofToString(frameIndex)+" sequence index\n";
    info += ofToString(appFPS)+"/"+ofToString(ofGetFrameRate(), 0)+" fps\n";
    info += ofToString(sequenceFPS)+" Sequence fps\n\n";
    info += "Keys:\nup & down arrows to\nchange app fps\n\n";
    info += "left & right arrows to\nchange sequence fps";
    info += "\n\n't' to toggle\nframe independent("+ofToString(bFrameIndependent)+")";
    
    ofDrawBitmapString(info, 15, 20);
}
Exemple #29
0
void KinectMotion::update(ofTexture & depthTex, bool isUpsideDown)
{
	if (isUpdateSlices)
	{
		isUpdateSlices = false;
		buildSlices();
	}
    
	depthSmallFbo.begin();
    ofPushMatrix();
	if (isUpsideDown)
	{
		ofTranslate(0, depthSmallFbo.getHeight());
		ofScale(1, -1);
	}
	else
	{
		ofTranslate(depthSmallFbo.getWidth(), 0);
		ofScale(-1, 1);
	}
    depthTex.draw(0, 0, depthSmallFbo.getWidth(), depthSmallFbo.getHeight());
    ofPopMatrix();
    depthSmallFbo.end();
    
    
    if (depthSlices.size() == 0) return;
    
	if (ofGetFrameNum() % 10 == 0)
	{
		int nearest = ofClamp(nearestGrey + 30, 120, 255);
		if (depthSlices[0].maxThreshold == -1 || abs(nearest - depthSlices[0].maxThreshold) > 30)
		{
			for (int i = 0; i < depthSlices.size(); i++)
			{
				float thresholdSection = nearest / depthSlices.size();
        
				// set the threshold of the depth slices - this limits the range e.g. 10 slices only tracking from 1m-4m - 30 cms per slice
				//int minThreshold = ofMap(255 - (i * thresholdSection + thresholdSection), 0, 255, sliceMinThreshold, sliceMaxThreshold);
				//int maxThreshold = ofMap(255 - (i * thresholdSection), 0, 255, sliceMinThreshold, sliceMaxThreshold);
			
				int minThreshold = nearest - (i * thresholdSection + thresholdSection);
				int maxThreshold = nearest - (i * thresholdSection);

				depthSlices[i].minThreshold = minThreshold;
				depthSlices[i].maxThreshold = maxThreshold;
			}
		}
	}
    
	
    for (int i = 0; i < depthSlices.size(); i++)
    {
        depthSlices[i].update(&depthSmallFbo.getTextureReference());
    }
    
    
//    for (int i = 0; i < 600; i += 3)
//    {
//        //ofVec3f v = ofVec3f(1.0, 1.0, 0.0);
//        ofVec3f v = ofVec3f(ofRandomuf(), ofRandomuf(), ofRandomuf());
//        //ofVec3f v = ofVec3f(ofRandom(255), ofRandom(255), ofRandom(255));
//        
//        motionData[i] = v.x;
//        motionData[i+1] = v.y;
//        motionData[i+2] = v.z;
//    }
    
//    depthMotionFbo.begin();
//    ofClear(1.0, 1.0, 1.0, 1.0);
//    depthMotionShader.begin();
//    depthMotionShader.setUniform1fv("motionData", motionData, 600);
//    depthTex.draw(0, 0, depthInW * 0.5, depthInH * 0.5);
//    depthMotionShader.end();
//    depthMotionFbo.end();

	
	// frame differencing
	//depthMotionFbo.begin();
 //   ofClear(1.0, 1.0, 1.0, 1.0);
	//depthTex.draw(0, 0, depthMotionFbo.getWidth(), depthMotionFbo.getHeight());
 //   depthMotionFbo.end();
	//depthMotionFbo.readToPixels(depthMotionPix);
	//absdiff(previousDepthMap, depthMotionPix, differenceImage);
	//differenceImage.update();
	//copy(depthMotionPix, previousDepthMap);
	//differenceMean = mean(toCv(differenceImage));
}
Exemple #30
0
//--------------------------------------------------------------
void ofxBulletPatch::updateMesh( ofMesh& aMesh ) {


    int totalNodes = getNumNodes();
    int totalFaces = getNumFaces();
    auto& tverts = aMesh.getVertices();
    
    if( _cachedMesh.getMode() == OF_PRIMITIVE_TRIANGLES ) {
        
        if( tverts.size() != totalFaces * 3 ) {
            tverts.resize( (getResolutionX()-1) * (getResolutionY()-1) * 6 );
        }
        
        auto& tnormals = aMesh.getNormals();
        if( tnormals.size() != tverts.size() ) {
            tnormals.resize( tverts.size() );
        }
        
        ofVec3f p1, p2, p3, p4;
        ofVec3f n1, n2, n3, n4;
        
        int ti = 0;
        for( int iy = 0; iy < getResolutionY()-1; iy++ ) {
            for( int ix = 0; ix < getResolutionX()-1; ix++ ) {
                
                int ni = iy * getResolutionX() + ix;
                p1.set( _softBody->m_nodes[ni].m_x.x(), _softBody->m_nodes[ni].m_x.y(), _softBody->m_nodes[ni].m_x.z() );
                n1.set( _softBody->m_nodes[ni].m_n.x(), _softBody->m_nodes[ni].m_n.y(), _softBody->m_nodes[ni].m_n.z() );
                ni = (iy+1) * getResolutionX() + ix;
                p2.set( _softBody->m_nodes[ni].m_x.x(), _softBody->m_nodes[ni].m_x.y(), _softBody->m_nodes[ni].m_x.z() );
                n2.set( _softBody->m_nodes[ni].m_n.x(), _softBody->m_nodes[ni].m_n.y(), _softBody->m_nodes[ni].m_n.z() );
                ni = (iy+1) * getResolutionX() + ix+1;
                p3.set( _softBody->m_nodes[ni].m_x.x(), _softBody->m_nodes[ni].m_x.y(), _softBody->m_nodes[ni].m_x.z() );
                n3.set( _softBody->m_nodes[ni].m_n.x(), _softBody->m_nodes[ni].m_n.y(), _softBody->m_nodes[ni].m_n.z() );
                ni = (iy) * getResolutionX() + ix+1;
                p4.set( _softBody->m_nodes[ni].m_x.x(), _softBody->m_nodes[ni].m_x.y(), _softBody->m_nodes[ni].m_x.z() );
                n4.set( _softBody->m_nodes[ni].m_n.x(), _softBody->m_nodes[ni].m_n.y(), _softBody->m_nodes[ni].m_n.z() );
                
                tverts[ti] = p1;
                tnormals[ti] = n1;
                ti += 1;
                
//                ni = (iy+1) * getResolutionX() + ix;
                tverts[ti] = p2;
                tnormals[ti] = n2;
                ti += 1;
                
//                ni = (iy+1) * getResolutionX() + ix+1;
                tverts[ti] = p3;
                tnormals[ti] = n3;
                ti += 1;
                
                
                
                //
//                ni = (iy+1) * getResolutionX() + ix+1;
                tverts[ti] = p3;
                tnormals[ti] = n3;
                ti += 1;
                
//                ni = (iy) * getResolutionX() + ix+1;
                tverts[ti] = p4;
                tnormals[ti] = n4;
                ti += 1;
                
//                ni = (iy) * getResolutionX() + ix;
                tverts[ti] = p1;
                tnormals[ti] = n1;
                ti += 1;
            }
            
        }
        
    }
    
    _lastMeshUpdateFrame = ofGetFrameNum();
}