void Plant::updateMesh(){ mbMesh.clear(); float perimeter = mbLine1.getPerimeter(); float distance = 10; float step = 0.02; for (float i = 0; i < 1; i += step) { float opacity; if(mbGrowAnimator.getValue()>i){ opacity = fadeAnimator.getValue(); }else{ opacity = 0; } ofVec2f dir1 = mbLine1.getTangentAtIndexInterpolated(ofMap(i, 0, 1, 0, mbLine1.size()-1)); ofColor col = color; mbMesh.addVertex(mbLine1.getPointAtPercent(i)); mbMesh.addColor(ofFloatColor(col, opacity)); col.setBrightness(ofMap(col.getBrightness(), 0, 255, 0, 200)); mbMesh.addVertex(mbLine2.getPointAtPercent(i)); mbMesh.addColor(ofFloatColor(col, opacity)); } childMeshes.clear(); childShadows.clear(); for (int i = 0; i < childLines1.size(); i++) { ofMesh mesh; mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); ofMesh shadow; shadow.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); Animator &a = cbGrowAnimators[i]; if(i>rig.childBranchesPoints.size()-1){ int parentIndex = i-rig.childBranchesPoints.size(); if(cbGrowAnimators[parentIndex].getValue()>0.5){ a.in(); } } for (float j = 0; j < 1; j += step) { float opacity = 1; ofColor col = color; if(a.getValue()>j){ opacity = ofMap(j, 0, step*8, 0, 1, true) * fadeAnimator.getValue(); }else{ opacity = 0; } // float opacity = ofMap(j, 0, step*8, 0, 1, true) * fadeAnimator.getValue(); mesh.addVertex(childLines1[i].getPointAtPercent(j)); mesh.addColor(ofFloatColor(col, opacity)); mesh.addVertex(childLines2[i].getPointAtPercent(j)); col.setBrightness(ofMap(j, 0, 1, col.getBrightness(), 120)); mesh.addColor(ofFloatColor(col, opacity)); } childMeshes.push_back(mesh); // add shadow // ofVec2f dir = rig.childBranchLines[i].getTangentAtIndex(0); // ofVec2f p = rig.childBranchLines[i].getVertices()[0]; // ofVec2f p1 = p + dir*10; // ofVec2f p2 = p + ofVec2f(0, 1)*40; // ofColor col = ofColor::black; // shadow.addVertex(p); // shadow.addColor(ofFloatColor(col, 0.2)); // shadow.addVertex(p1); // shadow.addColor(ofFloatColor(col, 0)); // shadow.addVertex(p2); // shadow.addColor(ofFloatColor(col, 0)); // // childShadows.push_back(shadow); } }
//-------------------------------------------------------------- LOOP void testApp::update(){ data.update(); kinect.update(); composer[1]->setTexture(kinect.getTextureReference()); composer[3]->setTexture(kinect.getDepthTextureReference()); if(kinect.isFrameNew()) { if (!bCalibrated){ bCalibrated = calibrator.update( composer[2] ); if (bCalibrated){ float diff = data.lowAltitude - data.topAltitude; data.lowAltitude = calibrator.getSurfaceDistance(); //data.topAltitude = data.lowAltitude - diff; data.topAltitude = calibrator.getCleanDistance(); } } else { kinect.setDepthClipping(data.topAltitude,data.lowAltitude); float *depthRaw = kinect.getDistancePixels(); numPixels = width * height; unsigned char * blobPixels = blobImage.getPixels(); float * depthFloatPixels = depthFloatImage.getPixels(); // ... and extract the range it neads int farThreshold = data.topAltitude; //minDist; int nearThreshold = data.lowAltitude; //maxDist; for(int i = 0; i < numPixels; i++, depthRaw++) { if(*depthRaw <= nearThreshold && *depthRaw >= farThreshold){ blobPixels[i] = 0; depthFloatPixels[i] += ofMap(*depthRaw, nearThreshold, farThreshold, 0.0f,1.0f); depthFloatPixels[i] *= 0.5; } else if ( *depthRaw < nearThreshold ){ if ( *depthRaw == 0) blobPixels[i] = 0; else blobPixels[i] = 255; } else if ( *depthRaw > farThreshold ){ blobPixels[i] = 0; depthFloatPixels[i] = 0.0f; } else { blobPixels[i] = 0; } int x = i%width; int y = i/height; if ( depthFloatPixels[i] <= data.waterLevel){ if (ofRandom(100000) < 1.0) atmosphere.setHotAt(x,y,0.5); } else { if (ofRandom(100000) < 1.0) atmosphere.setColdAt(x,y,0.5); } } // Save the results in a blobImage for the sky and depthFloatImage for the heightmap blobImage.flagImageChanged(); depthFloatImage.setFromPixels(depthFloatPixels, width, height, OF_IMAGE_GRAYSCALE ); depthFloatImage.reloadTexture(); // PROCESS DATA // ----------------------------------------------------- // Atmosphere atmosphere.update(blobImage, depthFloatImage); ofDisableAlphaBlending(); // Geosphere geosphere.update( depthFloatImage ); // Hydrosphere hydrosphere.update( atmosphere.getTextureReference(), geosphere ); // Biosphere biosphere.update(hydrosphere.getTextureReference(), geosphere ); // FinalMix textures.update(hydrosphere.getBlurTexture(), biosphere, geosphere); if (data.activeLayer == 0) composer[2]->setTexture(textures.getTextureReference()); else if (data.activeLayer == 1) composer[2]->setTexture( depthFloatImage.getTextureReference()); else if (data.activeLayer == 2) composer[2]->setTexture( geosphere.getAverage() ); else if (data.activeLayer == 3) composer[2]->setTexture( geosphere.getNormal() ); else if (data.activeLayer == 4) composer[2]->setTexture( geosphere.getNoise() ); else if (data.activeLayer == 5) composer[2]->setTexture( geosphere.getConditions() ); else if (data.activeLayer == 6) composer[2]->setTexture( hydrosphere.getTextureReference() ); else if (data.activeLayer == 7) composer[2]->setTexture( biosphere.getTextureReference() ); else if (data.activeLayer == 8) composer[2]->setTexture( biosphere.getAnimalLife() ); else if (data.activeLayer == 9) composer[2]->setTexture( atmosphere.getTextureReference() ); } if (bTerrain){ ofFloatPixels heightMap; heightMap.allocate(geosphere.getAverage().getWidth(), geosphere.getAverage().getHeight(), OF_PIXELS_RGBA); geosphere.getAverage().readToPixels(heightMap); ofFloatPixels norms; norms.allocate(geosphere.getNormal().getWidth(), geosphere.getNormal().getHeight(), OF_PIXELS_RGBA); geosphere.getNormal().readToPixels(norms); int width = heightMap.getWidth(); int height = heightMap.getHeight(); float flResolution = data.terrainResolution; float flHeightScale = (data.lowAltitude - data.topAltitude)*0.5; float textureScale = 1.0; if (data.activeLayer == 0) textureScale = 2.0; // Generate Vertex Field nVertexCount = (int) ( width * height * 6 / ( flResolution * flResolution ) ); pVertices = new ofVec3f[nVertexCount]; // Allocate Vertex Data pTexCoords = new ofVec2f[nVertexCount]; // Allocate Tex Coord Data pNormals = new ofVec3f[nVertexCount]; // Allocate Normals int nX, nZ, nTri, nIndex=0; // Create Variables float flX, flZ; for( nZ = 0; nZ < height-flResolution ; nZ += (int) flResolution ){ for( nX = 0; nX < width-flResolution ; nX += (int) flResolution ){ for( nTri = 0; nTri < 6; nTri++ ){ // Using This Quick Hack, Figure The X,Z Position Of The Point flX = (float) nX + ( ( nTri == 1 || nTri == 2 || nTri == 5 ) ? flResolution : 0.0f ); flZ = (float) nZ + ( ( nTri == 2 || nTri == 4 || nTri == 5 ) ? flResolution : 0.0f ); // Set The Data, Using PtHeight To Obtain The Y Value pVertices[nIndex].x = flX - ( width *0.5 ); pVertices[nIndex].y = heightMap.getColor((int)flX, (int)flZ).r * flHeightScale; pVertices[nIndex].z = flZ - ( height *0.5 ); // 3 0 --- 1 nTri reference // | \ \ | // | \ \ | // 4 --- 5 2 // Stretch The Texture Across The Entire Mesh pTexCoords[nIndex].x = flX * textureScale;// / width; pTexCoords[nIndex].y = flZ * textureScale;// / height; // Normals by vert pNormals[nIndex].x = norms.getColor((int)flX, (int)flZ).r; pNormals[nIndex].y = norms.getColor((int)flX, (int)flZ).b; pNormals[nIndex].z = norms.getColor((int)flX, (int)flZ).g; // Increment Our Index nIndex++; } } } vbo.setVertexData(pVertices, nVertexCount, GL_STREAM_DRAW); vbo.setNormalData(pNormals, nVertexCount, GL_STREAM_DRAW); vbo.setTexCoordData(pTexCoords, nVertexCount, GL_STREAM_DRAW); // Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card delete [] pVertices; pVertices = NULL; delete [] pTexCoords; pTexCoords = NULL; delete [] pNormals; pNormals = NULL; } } composer.update(); ofSetWindowTitle( ofToString( ofGetFrameRate())); }
//-------------------------------------------------------------- void testApp::update() { ofBackground(ofColor::black); // grab new frame and update colorImg with it. bool bNewFrame = false; #ifdef _USE_LIVE_VIDEO vidGrabber.update(); bNewFrame = vidGrabber.isFrameNew(); #else vidPlayer.update(); bNewFrame = vidPlayer.isFrameNew(); #endif if (bNewFrame) { #ifdef _USE_LIVE_VIDEO colorImg.setFromPixels(vidGrabber.getPixels(), 320,240); #else colorImg.setFromPixels(vidPlayer.getPixels(), 320,240); #endif grayImage = colorImg; // converts from color to greyscale float time = ofGetElapsedTimef(); // Update mesh from grayImage's pixels updateMesh(); // update a few variables based on time float timeToChangePalettes = 10.0f; int paletteIndex = (int) ((ofWrap( time, 0.0f, timeToChangePalettes ) / timeToChangePalettes ) * palettes.size()); if( palettes.size() > 0 && paletteIndex < palettes.size()) currPalette = &palettes.at(paletteIndex); linesHeight = 80.0f; lineSkip = 4; //ofMap( cos(time * 1.1f), -1.0f, 1.0f, 2, 25 ); // if we click, wait a bit until we auto orbit the camera if( (time - lastClickTime) > 4.0 ) { float orbitLong = ofMap( ofNoise(time*0.2f), 0.0f, 1.0f, -50.0f, 50.0f ) ; float orbitLat = ofMap( ofNoise( (time+111.0f)*0.3f), 0.0f, 1.0f, 0.0f, -100.0f ) ; float orbitRadius = ofMap( ofNoise( (time-123.0f)*0.45f), 0.0f, 1.0f, 100.0f, 250.0f ) ; camera.orbit(orbitLong, orbitLat, orbitRadius ); } fbo.begin(); ofClear(0, 0, 0, 0); //clear our Fbo memory ofEnableDepthTest(); //enable 3d camera.begin(); //start our camera viewpoint ofTranslate( (grayImage.getWidth() * -0.5f) * imageToSpaceScaling.x, //move x 0.0f, //move y (grayImage.getHeight() * -0.5f) * imageToSpaceScaling.z //move z ); ofSetColor( ofColor::white ); //start with a white mesh colorFromHeightShader.begin(); //begin our shader if( currPalette != NULL ) //make sure we have a palette { //we pass our palette to the shader colorFromHeightShader.setUniformTexture( "u_paletteSampler", currPalette->getTextureReference(), 1 ); } //we pass our linesHeight to the shader colorFromHeightShader.setUniform1f("u_maxHeight", linesHeight ); //we draw our mesh (currently in OF_PRIMITIVE_LINES mode) mesh.draw(); colorFromHeightShader.end(); //stop our shader operation camera.end(); //end our camera view ofDisableDepthTest(); //ending 3d fbo.end(); //stop drawing inside the fbo } }
//------------------------------------------------------------------ void explosion::draw() { ofSetRectMode(OF_RECTMODE_CENTER); if(explode == false){ if(ofGetElapsedTimef()>17){ posa.x-=3; if(posa.x < 0){ posa.x = ofGetWidth(); } } if(ofGetElapsedTimef()<17){ posa.y+=3; if(posa.y > ofGetHeight()){ posa.y = 0; } } float timer = sin(ofGetElapsedTimef()*ofRandom(10)); float alph = ofMap(timer,-1,1, 128, 0); ofColor c2(c1,alph); ofSetColor(c2); ofRect(posa.x, posa.y, 15,15); } if(explode == true){ for(int i =0; i< num; i++){ posb.x = posa.x+ radius*cos(angle + PI*2/num*i); posb.y = posa.y+ radius*-sin(angle + PI*2/num*i); myPct += speed; if(myPct>1)myPct = 1; pct = powf(myPct, 1); pos.x = (1-pct)*posa.x + pct* posb.x; pos.y = (1-pct)*posa.y + pct* posb.y; float alph = ofMap(pct,0,1, 255, 0); ofColor c2(c3,alph); ofSetColor(c2); ofRect(pos.x, pos.y, rectsize,rectsize); if(myPct>1)myPct = 0; pct = powf(myPct, shaper); pos.x = (1-pct)*posa.x + pct* posb.x; pos.y = (1-pct)*posa.y + pct* posb.y; ofRect(pos.x, pos.y, rectsize,rectsize); } } }
float followerBig::map(float in, float inMin,float inMax, float outMin, float outMax, float shaper){ float pct = ofMap (in, inMin, inMax, 0, 1, true); pct = powf(pct, shaper); float out = ofMap(pct, 0,1, outMin, outMax, true); return out; }
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)); }
//-------------------------------------------------------------- void testApp::update() { time = ofGetElapsedTimef(); cose = cos(time)*amplitude; sine = sin(time)*amplitude; centerX = ofGetWidth()/2; centerY = ofGetHeight()/2; diameter = ofMap(sine, -amplitude , amplitude , 10,200); pointX += (targetX - pointX)*easing; pointY += (targetY - pointY)*easing; yellowBall.x = yellowBall.x + yellowBall.vx; yellowBall.y = yellowBall.y + yellowBall.vy; whiteBall.x = whiteBall.x + whiteBall.vx; whiteBall.y = whiteBall.y + whiteBall.vy; redBall.x = redBall.x + redBall.vx; redBall.y = redBall.y + redBall.vy; greenBall.x = greenBall.x + greenBall.vx; greenBall.y = greenBall.y + greenBall.vy; grayBall.x = grayBall.x + grayBall.vx; grayBall.y = grayBall.y + grayBall.vy; purpleBall.x = purpleBall.x + purpleBall.vx; purpleBall.y = purpleBall.y + purpleBall.vy; orangeBall.x = orangeBall.x + orangeBall.vx; orangeBall.y = orangeBall.y + orangeBall.vy; blueBall.x = blueBall.x + blueBall.vx; blueBall.y = blueBall.y + blueBall.vy; if (yellowBall.x<0 || yellowBall.x > ofGetWidth()) { yellowBall.vx = -yellowBall.vx/2; } if (yellowBall.y<0 || yellowBall.y > ofGetHeight()) { yellowBall.vy = -yellowBall.vy/2; } if (whiteBall.x<0 || whiteBall.x > ofGetWidth()) { whiteBall.vx = -whiteBall.vx; } if (whiteBall.y<0 || whiteBall.y > ofGetHeight()) { whiteBall.vy = -whiteBall.vy; } if (redBall.x<0 || redBall.x > ofGetWidth()) { redBall.vx = -redBall.vx; } if (redBall.y<0 || redBall.y > ofGetHeight()) { redBall.vy = -redBall.vy; } if (greenBall.x<0 || greenBall.x > ofGetWidth()) { greenBall.vx = -greenBall.vx/2; } if (greenBall.y<0 || greenBall.y > ofGetHeight()) { greenBall.vy = -greenBall.vy/2; } if (grayBall.x<0 || grayBall.x > ofGetWidth()) { grayBall.vx = -grayBall.vx; } if (grayBall.y<0 || grayBall.y > ofGetHeight()) { grayBall.vy = -grayBall.vy; } if (purpleBall.x<0 || purpleBall.x > ofGetWidth()) { purpleBall.vx = -purpleBall.vx; } if (purpleBall.y<0 || purpleBall.y > ofGetHeight()) { purpleBall.vy = -purpleBall.vy; } if (orangeBall.x<0 || orangeBall.x > ofGetWidth()) { orangeBall.vx = -orangeBall.vx/2; } if (orangeBall.y<0 || orangeBall.y > ofGetHeight()) { orangeBall.vy = -orangeBall.vy/2; } if (blueBall.x<0 || blueBall.x > ofGetWidth()) { blueBall.vx = -blueBall.vx; } if (blueBall.y<0 || blueBall.y > ofGetHeight()) { blueBall.vy = -blueBall.vy; } }
//-------------------------------------------------------------- void testApp::drawtheMidi() { ofSetColor(255); text<< "port:" << midiMessage.portNum; ofDrawBitmapString(text.str(),250,20); text.str(""); // clear text << "control: " << midiMessage.control; ofDrawBitmapString(text.str(), 350, 20); text.str(""); // clear text << "value: " << midiMessage.value; ofDrawBitmapString(text.str(), 450, 20); text.str(""); // clear if (midiMessage.control == 0) { opticalFlow.setStrength(ofMap(midiMessage.value, 0, 127, 0, 100)); } else if (midiMessage.control == 16) { velocityMask.setStrength(ofMap(midiMessage.value, 0, 127, 0, 10)); } // ===== cell and speed else if (midiMessage.control == 1) { fluid.setSpeed(ofMap(midiMessage.value, 0, 127, 0, 100)); } else if (midiMessage.control == 17) { fluid.setCellSize(ofMap(midiMessage.value, 0, 127, 0, 2)); } // ===== fluid else if (midiMessage.control == 2) { fluid.setNumJacobiIterations(ofMap(midiMessage.value, 0, 127, 0, 100)); } else if (midiMessage.control == 18) { fluid.setViscosity(ofMap(midiMessage.value, 0, 127, 0, 1)); } else if (midiMessage.control == 3) { fluid.setVorticity(ofMap(midiMessage.value, 0, 127, 0, 1)); } else if (midiMessage.control == 19) { fluid.setDissipation(ofMap(midiMessage.value, 0, 127, 0, 0.02)); } // ===== particle else if (midiMessage.control == 4) { particleFlow.setSize(ofMap(midiMessage.value, 0, 127, 0, 10)); } else if (midiMessage.control == 20) { particleFlow.setLifeSpan(ofMap(midiMessage.value, 0, 127, 0, 10)); } else if (midiMessage.control == 5) { particleFlow.setSizeSpread(ofMap(midiMessage.value, 0, 127, 0, 1)); } else if (midiMessage.control == 21) { particleFlow.setBirthChance(ofMap(midiMessage.value, 0, 127, 0, 1)); } // ===== distence and color else if (midiMessage.control == 23) { opticalFlow.setThreshold(ofMap(midiMessage.value, 0, 127, 0, 0.2)); } else if (midiMessage.control == 7) { velocityMask.setSaturation(ofMap(midiMessage.value, 0, 127, 0, 5)); } //-------------------- BlendMode --------------- else if (midiMessage.control == 65) { numberBlend = 1; } else if (midiMessage.control == 66) { numberBlend = 2; } else if (midiMessage.control == 67) { numberBlend = 3; } else if (midiMessage.control == 68) { numberBlend = 4; } else if (midiMessage.control == 69) { numberBlend = 5; } else if (midiMessage.control == 70) { numberBlend = 6; } }
void MyKeeponControlPanel::sendSideSpeed() { if(bSerialInited) { string msg = "SPEED PONSIDE "+ofToString((int)ofMap(mGazeValues.sideSpeed, 0,1, 64,250, true))+";"; mSerial.writeBytes((unsigned char*)msg.c_str(), msg.size()); } }
void testApp::drawUI(){ int borderPadding = 60; ofPushMatrix();{ ofTranslate(ofGetWindowSize()/2); //INSTRUCTIONS for(int i = 0; i < 1; i++){ ofPushMatrix(); ofRotate(i*180); ofTranslate(0, ofGetWindowHeight()/2 - borderPadding); ofRotate(180); ofScale(0.23, 0.23); //draw bounding boxes ofSetColor(0, 255 * 0.4); ofRectangle A = instructions.getStringBoundingBox(instructionA, -instructions.stringWidth(instructionA)/2, 0); ofRect(A.x, A.y, A.width, A.height); ofRectangle B = instructions.getStringBoundingBox(instructionB, -instructions.stringWidth(instructionB)/2, instructions.getLineHeight()); ofRect(B.x, B.y, B.width, B.height); //draw text ofSetColor(instructCol); instructions.drawString(instructionA, -instructions.stringWidth(instructionA)/2, 0); instructions.drawString(instructionB, -instructions.stringWidth(instructionB)/2, instructions.getLineHeight()); ofPopMatrix(); } //STATUS int num; if(attractorSize < 100){ num = 2; } else if(attractorSize < 200){ num = 3; } else { num = 4; } for(int i = 0; i < num; i++){ ofPushMatrix(); ofRotate(360/num * i + (ofGetElapsedTimef() * 10)); ofTranslate(0, attractorSize + attractorSize * 0.1); statusScale = ofMap(attractorSize, 0, 300, 0.08, 0.23); ofScale(statusScale, statusScale); //draw text ofSetColor(statusCol); status.drawString(statusA, -status.stringWidth(statusA)/2, 0); status.drawString(statusB, -status.stringWidth(statusB)/2, status.getLineHeight()); ofPopMatrix(); } //ZOOM STUFF if(zooming){ ofPushStyle(); ofSetRectMode(OF_RECTMODE_CENTER); ofSetColor(zoomSquareCol); ofNoFill(); ofSetLineWidth(zoomSquareThick); ofRect(0, 0, zoomSquareWidth, zoomSquareWidth); ofPopStyle(); } }ofPopMatrix(); }
void testApp::debugVis(){ ofPushStyle(); ofSetColor(255); ofNoFill(); ofRect(ofGetWindowWidth()/2 - ofGetWindowHeight()/2, 0, ofGetWindowHeight(), ofGetWindowHeight()); ofSetColor(255, 0, 0); ofDrawBitmapString("Framerate: " + ofToString(ofGetFrameRate()), 20, 30); ofDrawBitmapString("Number of Particles: " + ofToString(pList.size()), 20, 45); ofDrawBitmapString("Disturbed not dead: " + ofToString(numDisturbed), 20, 60); ofDrawBitmapString("Dead Particles: " + ofToString(numDead), 20, 75); ofDrawBitmapString("Attractor Size: " + ofToString(attractorSize), 20, 90); ofDrawBitmapString("Number of blobs detected: " + ofToString(contourFinder.blobs.size()), 20, 120); if(blobDirection.size() > 0){ ofDrawBitmapString("Blobs[0] magnitude: " + ofToString(blobDirection[0].length()), 20, 135); } ofPopStyle(); //draw kinect stuff contourFinder.draw(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); // for(int i = 0; i < contourFinder.blobs.size(); i++){ // ofPushStyle(); // ofSetColor(255, 0, 0); // float thisX = ofMap(contourFinder.blobs[i].centroid.x, 0, kinect.width, 0, ofGetWindowWidth()); // float thisY = ofMap(contourFinder.blobs[i].centroid.y, 0, kinect.height, 0, ofGetWindowHeight()); // ofCircle(thisX, thisY, 10); // //// ofNoFill(); //// ofCircle(thisX, thisY, disturbRad); // // // ofPopStyle(); // } for(int i = 0; i < contourFinder.blobs.size(); i++){ //for( vector<ofxCvBlob>:: iterator thisBlob = contourFinder.blobs.begin(); thisBlob != contourFinder.blobs.end(); thisBlob++){ //map the position of the blob to the screen size float mapBlobX = ofMap(contourFinder.blobs[i].centroid.x, 0, kinect.width, 0, ofGetWindowWidth()); float mapBlobY = ofMap(contourFinder.blobs[i].centroid.y, 0, kinect.height, 0, ofGetWindowHeight()); // //subtract position of centroid from position of particle // ofVec2f distBlob = (it -> pos) - ofVec2f(mapBlobX, mapBlobY); // // //count as disturbed if within radius (circular boundary) // if(distBlob.lengthSquared() < disturbRad * disturbRad){ // it -> disturbed = true; // } //map the size of the bounding box to the screen size float mapBlobBoxW = ofMap(contourFinder.blobs[i].boundingRect.width, 0, kinect.width, 0, ofGetWindowWidth()); float mapBlobBoxH = ofMap(contourFinder.blobs[i].boundingRect.height, 0, kinect.height, 0, ofGetWindowHeight()); ofPushStyle(); ofSetColor(0, 255, 0); ofCircle(mapBlobX, mapBlobY, 10); ofNoFill(); ofRect(mapBlobX - mapBlobBoxW/2, mapBlobY - mapBlobBoxH/2, mapBlobBoxW, mapBlobBoxH); ofPopStyle(); } }
//-------------------------------------------------------------- void testApp::draw(){ if(narrativeState == 0){ } else if(narrativeState == 1){ //draw particles for( vector<Particle>::iterator it = pList.begin(); it!=pList.end(); it++){ if(it -> dead == false){ it -> draw(); } } //Draw Attractor // ofSetColor(255, 230, 165, 255*0.09); ofColor out = ofColor(255, 240, 200, 80); ofColor in = ofColor(255, 212, 100, 80); int numBlobs = 100; for(int i = 0; i < numBlobs; i++){ // ofSetColor(255, 255 - 255 * i/numBlobs, 225 - 225 * i/numBlobs, 255 * 0.08); ofColor thisCol = out.lerp(in, 0.01); ofSetColor(thisCol); float blobWobble = ofMap(i, 0, numBlobs, 0.6, 0.1); perlinBlob(attractorSize - attractorSize * i/numBlobs, blobWobble, 0 + i*2000, 36*i); } } else if(narrativeState == 2){ //draw particles for( vector<Particle>::iterator it = pList.begin(); it!=pList.end(); it++){ if(it -> dead == false){ it -> draw(); } } //Draw Attractor ofColor out = ofColor(255, 255, 255, 100); ofColor in = ofColor(255, 0, 0, 100); int numBlobs = 100; for(int i = 0; i < numBlobs; i++){ ofSetColor(255, 255 - 255 * i/numBlobs, 225 - 225 * i/numBlobs, 255 * 0.08); // ofSetColor(in.lerp(out, i/numBlobs)); float blobWobble = ofMap(i, 0, numBlobs, 0.6, 0.1); perlinBlob(attractorSize - attractorSize * i/numBlobs, blobWobble, 0 + i*2000, 36*i); } //adds a little shading outside the central circle for(int i = 0; i < 5; i++){ ofSetColor(0, 255 * 0.03); perlinBlob(attractorSize - attractorSize * 0.8, 0.6, 0 + i*2000, 36*i); } //draw central red circle ofSetColor(255, 0, 0); ofCircle(ofGetWindowSize()/2, attractorSize*0.1); } //draw UI drawUI(); //Show all the debugging visuals if(debugVisuals){ debugVis(); } //----------after everything else is done---------- //lets take note of the old mouse position oldMousePos.set(mouseX, mouseY); //Also, keep track of old blob positions and directions //start by clearing out the vectors oldBlobPos.clear(); //if there are blobs then lets allocate the same number of slots as there are blobs if(contourFinder.blobs.size() > 0){ oldBlobPos.resize(contourFinder.blobs.size()); } //then lets fill it with the positions of all the blobs for(int i = 0; i < oldBlobPos.size(); i++){ oldBlobPos[i].set(contourFinder.blobs[i].centroid); } }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ int swap = ofMap(key, 48, 57, 0, 9); if((swap <= 9)&&(swap >= 0)){ if(swap < maxNumber){ for(int i = 0; i < maxNumber; i++){ mapping[i]->deactivate(); } mapping[swap]->activate(); swapGloble = swap; } } switch (key) { case 's': save(); break; case 'l': loadMe(); break; case 'f': CGDisplayHideCursor(kCGDirectMainDisplay); ofToggleFullscreen(); break; case ' ': if(debug == 0){ debug = 1; } else{ debug = 0; } for(int i = 0; i < maxNumber; i++){ mapping[i]->debugSet(debug); } break; case 13: maxNumber ++; mapping[maxNumber-1] = new ofxQuad(); vid.push_back(ofVideoPlayer()); vid[maxNumber-1].loadMovie(dir.getPath(0)); width = vid[maxNumber-1].getWidth() * (maxNumber-hozpertion); if((width + vid[maxNumber-1].getWidth()) > ofGetWidth() ){ hozpertion = maxNumber + 1; height += vid[maxNumber-1].getHeight(); width = 10; } mapping[maxNumber-1]->setup(width+10,10+height, 200, 200, ofGetWidth(), ofGetHeight(),maxNumber-1); mapping[maxNumber-1]->deactivate(); vid[maxNumber-1].play(); mapping[maxNumber-1]->debugSet(0); break; case 357: if( load >=(int)dir.size()-1){ load = 0; } else{ load += 1; } vid[swapGloble].loadMovie(dir.getPath(load)); break; case 359: if( load <=0){ load = (int)dir.size()-1; } else{ load -= 1; } vid[swapGloble].loadMovie(dir.getPath(load)); break; default: break; } // cout << " me first " << endl; }
void shaderBlur::blur(int numPasses, float blurDist){ noPasses = ofClamp(numPasses, 1, 100000); blurDistance = blurDist; ofxFBOTexture * src, * dst; src = &fbo1; dst = &fbo2; if( blurDist > 0 ){ for(int i = 0; i < noPasses; i++){ float blurPer = blurDistance * ofMap(i, 0, noPasses, 1.0/noPasses, 1.0); //first the horizontal shader shaderH.setShaderActive(true); shaderH.setUniformVariable1f("blurAmnt", blurDistance); dst->swapIn(); // dst->setupScreenForMe(); glViewport(0, 0, w, h); float halfFov, theTan, screenFov, as; screenFov = 120.0f; float eyeX = (float)w / 2.0; float eyeY = (float)h / 2.0; halfFov = PI * screenFov / 360.0; theTan = tanf(halfFov); float dist = eyeY / theTan; float nearDist = dist / 10.0; // near / far clip plane float farDist = dist * 10.0; as = (float)w/(float)h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(screenFov, as, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0.0, 0.0, 1.0, 0.0); glScalef(1, -1, 1); // invert Y axis so increasing Y goes down. glTranslatef(0, -h, 0); // shift origin up to upper-left corner. src->draw(0, 0); dst->swapOut(); // ofSetupScreen(); shaderH.setShaderActive(false); //now the vertical shader shaderV.setShaderActive(true); shaderV.setUniformVariable1f("blurAmnt", blurDistance); src->swapIn(); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(screenFov, as, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0.0, 0.0, 1.0, 0.0); glScalef(1, -1, 1); // invert Y axis so increasing Y goes down. glTranslatef(0, -h, 0); // shift origin up to upper-left corner. dst->draw(0,0); src->swapOut(); shaderV.setShaderActive(false); // ofxFBOTexture * tmp = src; // src = dst; // dst = tmp; } } }
void RecordScene::update() { fft.update(); //Get current spectrum with N bands // float *val = ofSoundGetSpectrum( N ); float *val = new float[N]; fft.getFftPeakData(val, N); //We should not release memory of val, //because it is managed by sound engine //Update our smoothed spectrum, //by slowly decreasing its values and getting maximum with val //So we will have slowly falling peaks in spectrum for ( int i=0; i<N; i++ ) { spectrum[i] *= 0.97; //Slow decreasing spectrum[i] = max( spectrum[i], val[i] ); } //Update particles using spectrum values //Computing dt as a time between the last //and the current calling of update() float time = ofGetElapsedTimef(); float dt = time - time0; dt = ofClamp( dt, 0.0, 0.1 ); time0 = time; //Store the current time //Update Rad and Vel from spectrum //Note, the parameters in ofMap's were tuned for best result //just for current music track // Rad = ofMap( spectrum[ bandRad ], 1, 3, 400, 800, true ); Rad = ofMap( shareData->fft->getAveragePeak(), 0, 1, 400, 800, true ); Vel = ofMap( spectrum[ bandVel ], 0, 0.1, 0.05, 0.1 ); //Update particles positions for (int j=0; j<n; j++) { tx[j] += Vel * dt; //move offset ty[j] += Vel * dt; //move offset //Calculate Perlin's noise in [-1, 1] and //multiply on Rad p[j].x = ofSignedNoise( tx[j] ) * Rad; p[j].y = ofSignedNoise( ty[j] ) * Rad; } delete[] val; if(isRecording) { if(ofGetElapsedTimef() - startRecordTime > MAX_RECORD_DURATION) { shareData->nextScent = 1; // startRecordTime = ofGetElapsedTimef(); } if(endAngle < 270) { endAngle = ofMap(ofGetElapsedTimef(), startRecordTime, startRecordTime + MAX_RECORD_DURATION, -90, 270, true); } angleArc.clear(); float radius = recordRect.getWidth()*.5+2; angleArc.arc( 0, 0, radius, radius, -90, endAngle); angleArc.close(); } //this is just to draw the arc that represents the angle }
void MyKeeponControlPanel::update(){ // check if we have to update the list of serial connections on this panel if(bUpdateSerialList){ mSerialList->clearToggles(); for(int i=0; i<theSerials.size(); i++){ mSerialList->addToggle(theSerials.at(i)); } bUpdateSerialList = false; } // clear serial pipe if(bSerialInited) { mSerial.flush(); } // check if we have to update due to sync if(bUpdateGazeGuiFromValues){ m2DPad->setValue(ofPoint(mGazeValues.pan,mGazeValues.tilt)); mPanSpeed->setValue(mGazeValues.panSpeed); mTiltSpeed->setValue(mGazeValues.tiltSpeed); mSideSpeed->setValue(mGazeValues.sideSpeed); bUpdateGazeGuiFromValues = false; } if(bUpdateDanceGuiFromValues) { mTempoDance->setValue(mDanceValues.tempo); mPanDance->setToggle(0, 0, mDanceValues.pan.enabled); mPanDance->setToggle(0, 1, mDanceValues.pan.doubled); mPanDance->setToggle(0, 2, mDanceValues.pan.reversed); // mTiltDance->setToggle(0, 0, mDanceValues.tilt.enabled); mTiltDance->setToggle(0, 1, mDanceValues.tilt.doubled); mTiltDance->setToggle(0, 2, mDanceValues.tilt.reversed); // mSideDance->setToggle(0, 0, mDanceValues.side.enabled); mSideDance->setToggle(0, 1, mDanceValues.side.doubled); mSideDance->setToggle(0, 2, mDanceValues.side.reversed); bUpdateDanceGuiFromValues = false; } unsigned long long tBeat = ofMap(mDanceValues.tempo,0,1, 1000, 500); if(ofGetElapsedTimeMillis()-lastHalfBeat > tBeat/2) { // whether this is the beat or the half-beat bool bOnTheBeat = (ofGetElapsedTimeMillis()%tBeat) < (tBeat/2); // pan dance: enabled && (on the beat or double-time) if((mDanceValues.pan.enabled) && (bOnTheBeat || mDanceValues.pan.doubled)) { // magick to figure out position if((bOnTheBeat&&(mDanceValues.pan.doubled||mDanceValues.beatPos)) ^ mDanceValues.pan.reversed) { mGazeValues.pan = mDanceValues.panCenter - 0.11; } else { mGazeValues.pan = mDanceValues.panCenter + 0.11; } } // tilt dance: enabled && (on the beat or double-time) if((mDanceValues.tilt.enabled) && (bOnTheBeat || mDanceValues.tilt.doubled)) { // magick to figure out position if((bOnTheBeat&&(mDanceValues.tilt.doubled||mDanceValues.beatPos)) ^ mDanceValues.tilt.reversed) { mGazeValues.tilt = mDanceValues.tiltCenter - 0.4; } else { mGazeValues.tilt = mDanceValues.tiltCenter + 0.4; } } // side dance: enabled && (on the beat or double-time) if((mDanceValues.side.enabled) && (bOnTheBeat || mDanceValues.side.doubled)) { // magick to figure out position // mDanceValues.side.reversed selects between pon and side // this is pon if(mDanceValues.side.reversed) { mGazeValues.side = 2; } // this is side else { if(bOnTheBeat&&(mDanceValues.side.doubled||mDanceValues.beatPos)) { mGazeValues.side = 1; } else { mGazeValues.side = -1; } } } // send values if(mDanceValues.pan.enabled || mDanceValues.tilt.enabled) { sendPanAndTilt(); } if(mDanceValues.side.enabled) { sendSide(); } // flip beatPos on whole beats mDanceValues.beatPos ^= bOnTheBeat; lastHalfBeat = ofGetElapsedTimeMillis(); } // scripting control if(isScriptLoaded && isScriptPlaying) { // there's a command to process and its time to process it if(mScript.hasCommand() && (ofGetElapsedTimeMillis()>lastScriptCommand+mScript.getDelay())) { // send command to serial if(bSerialInited) { mSerial.writeBytes((unsigned char*)mScript.getCommand().c_str(), mScript.getCommand().size()); } cout << mScript.getDelay() << " " << mScript.getCommand() << endl; mScript.getNextCommand(); lastScriptCommand = ofGetElapsedTimeMillis(); } // no more commands else if (!mScript.hasCommand()) { mPlay->setColorBack(OFX_UI_COLOR_BACK); isScriptPlaying = false; } } }
void GestureCursor::parseOscMessage( ofxOscMessage * m ) { /* stringstream ss ; ss << " address " << m.getAddress() << endl << "[0] - status " << m.getArgAsInt32( 0 ) << endl << "[1] body id - " << m.getArgAsInt32( 1 ) << endl ; ss << "[2] - x " << m.getArgAsFloat( 2 ) << endl << "[3] - y " << m.getArgAsFloat( 3 ) << endl ; ofLogNotice( "incoming OSC MESSAGE " ) << endl << ss.str() << endl ; */ int bodyId = m->getArgAsInt32( 0 ) ; int handStatus = m->getArgAsInt32( 1 ) ; CURSOR_STATUS pStatus = status ; switch ( handStatus ) { case 1 : status = CLOSED ; break ; case 2 : status = OPEN ; break ; case 3 : status = LASSO; break ; default : status = LOST ; break ; } Tweenzor::add( &normalizedScreen.x , normalizedScreen.x , m->getArgAsFloat( 2 ) , 0.0f , smoothing ) ; Tweenzor::add( &normalizedScreen.y , normalizedScreen.y , m->getArgAsFloat( 3 ) , 0.0f , smoothing ) ; screenPosition.x = ofLerp( ofMap( normalizedScreen.x , 0.0f , 1.0f , 0.0f , ofGetWidth() , true ) , screenPosition.x ,smoothing ) ; screenPosition.y = ofLerp( ofMap( normalizedScreen.y , 0.0f , 1.0f , 0.0f , ofGetHeight() , true ) , screenPosition.y , smoothing ) ; Tweenzor::add( &normalizedWorld.x , normalizedWorld.x , m->getArgAsFloat( 4 ) , 0.0f , smoothing ) ; // * worldScale ; Tweenzor::add( &normalizedWorld.y , normalizedWorld.y , m->getArgAsFloat( 5 ) , 0.0f , smoothing ) ; //* worldScale ; Tweenzor::add( &normalizedWorld.z , normalizedWorld.z , m->getArgAsFloat( 6 ) - 1.0 , 0.0f , smoothing ) ; // * worldScale ; worldPosition = normalizedWorld * worldScale ; //Calculate some state changes... if ( pStatus != LOST && status == LOST ) { dragLostTimer.start( false , false ) ; // ofNotifyEvent( UP , id ) ; } if ( pStatus == OPEN && status == CLOSED ) { //GestureEvents ofNotifyEvent( GestureEvents::DOWN , id ) ; } if ( pStatus == CLOSED && status == CLOSED ) { ofNotifyEvent( GestureEvents::DRAG , id ) ; } if ( pStatus == CLOSED && status != CLOSED ) { //if ( dragLostTimer.bIsRunning == false ) dragLostTimer.start( false , false ) ; status = CLOSED ; ofNotifyEvent( GestureEvents::DRAG , id ) ; } }
//-------------------------------------------------------------- void testApp::newMidiMessage(ofxMidiMessage& msg) { // Ignore timing messages if (msg.status!=MIDI_TIME_CLOCK){ // make a copy of the latest message midiMessage = msg; if(midiMessage.status==MIDI_NOTE_ON) m_vecKeys[midiMessage.pitch-m_iKeyOffset] = true; if(midiMessage.status==MIDI_NOTE_OFF) m_vecKeys[midiMessage.pitch-m_iKeyOffset] = false; if(midiMessage.status==MIDI_PITCH_BEND) m_iPitch = midiMessage.value; if(midiMessage.status==MIDI_CONTROL_CHANGE) { switch (midiMessage.control) { case 1: m_iMod = midiMessage.value; break; case 74: m_iCutOff = midiMessage.value; break; case 71: m_iResonance = midiMessage.value; break; case 73: m_iAttack = midiMessage.value; break; case 72: m_iRelease = midiMessage.value; break; } } if(midiMessage.status==MIDI_PROGRAM_CHANGE) { m_sText.str(""); // clear int value = midiMessage.value; if(value>=0 && value<8) m_sText << "TRANCE A." << value+1; if(value>=64 && value<72) m_sText << "TRANCE B." << value-64+1; if(value>=8 && value<16) m_sText << "TECHNO/HOUSE A." << value+1; if(value>=72 && value<80) m_sText << "TECHNO/HOUSE B." << value-72+1; if(value>=16 && value<24) m_sText << "ELECTRONICA A." << value+1; if(value>=80 && value<88) m_sText << "ELECTRONICA B." << value-80+1; if(value>=24 && value<32) m_sText << "DNB/BREAKS A." << value+1; if(value>=88 && value<96) m_sText << "DNB/BREAKS B." << value-88+1; if(value>=32 && value<40) m_sText << "HIPHOP/VINTAGE A." << value+1; if(value>=96 && value<104) m_sText << "HIPHOP/VINTAGE B." << value-96+1; if(value>=40 && value<48) m_sText << "RETRO A." << value+1; if(value>=104 && value<112) m_sText << "RETRO B." << value-104+1; if(value>=48 && value<56) m_sText << "S.E./HIT A." << value+1; if(value>=112 && value<120) m_sText << "S.E./HIT B." << value-112+1; if(value>=56 && value<64) m_sText << "VOCODER A." << value+1; if(value>=120 && value<128) m_sText << "VOCODER B." << value-120+1; } } else { float time = m_fTime; m_fTime = ofGetElapsedTimeMillis(); m_fTempo = ofMap(1.0/(m_fTime-time),0.008,0.125,20,300); } }
//-------------------------------------------------------------- void RuleNine::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); } ofSetColor(255); Inst.draw(590,ofGetHeight()-150); for (int k = 0; k < 2; k ++) { for (int j = 0; j < 3; j ++) { ofSetColor(255); Mate.draw(j*455+430,k*400-330,73,130); Mate.draw(j*445+20,k*400+686,73,130);//about to switch him into his own class // Mate.draw(j*400,k*400-340,100+(10 * sin(counter)),210+(10 * sin(counter))); //about to switch him into his own class CompyImages.getFrameForTime(ofGetElapsedTimef())->draw((j*800)-660,610*k+10,240,240); //the frame and the current frame CompyImages.getFrameForTime(ofGetElapsedTimef())->draw((j*580)-50,410*k-130,240,240); //the frame and the current frame } } ofSetColor(255); frame.draw(340,220); ofSetColor(73,66,54); ofSetColor(200, 200, 200); int videowidth = 630; int videoheight = 342; grayImage.draw(360, 240,videowidth,videoheight); IplImage* eig = cvCreateImage( cvGetSize(grayImage.getCvImage()), 32, 1 ); IplImage* temp = cvCreateImage( cvGetSize(grayImage.getCvImage()), 32, 1 ); cvReleaseImage( &eig ); cvReleaseImage( &temp ); grayImage.draw(360, 240,videowidth,videoheight); //id like to tint the video but not sure how for (int i=400; i<grayImage.width; i++){ for (int j=200; j< grayImage.height; j++){ float brightness = myColor.getBrightness(); // get the brightness of the color float length = ofMap(brightness,0,255,1,12); if (brightness >=0 && brightness < 40){ colorvar = ofColor :: darkTurquoise; } else if (brightness >= 40 && brightness < 69 ){ colorvar = ofColor :: cornflowerBlue; } else if (brightness >= 69 && brightness <= 70 ){ colorvar = ofColor :: coral; } else if (brightness > 70 && brightness <=120){ colorvar = ofColor :: aqua; } else if (brightness > 120 && brightness <=200){ colorvar = ofColor :: cyan; } else if (brightness > 200 && brightness <215){ colorvar = ofColor :: lawnGreen; } else if (brightness > 215 && brightness <255){ colorvar = ofColor :: yellow; } else if (brightness == 255){ colorvar = ofColor :: pink; } } } for (int i = 0; i < allClouds.size(); i++) { //drawing all the clouds, every frame allClouds[i].draw(); } ofSetColor(73,66,54); type.draw(470,105); }
//-------------------------------------------------------------- void testApp::drawKeyboard() { int idx = 0; ofPushMatrix(); ofTranslate(10,60); ofPushStyle(); // White Keys ofPushMatrix(); for(int i=0;i<m_iNumOctaves;i++){ for(int j=0; j<7;j++){ idx = 12*i+2*j; if (j>2) --idx; if (m_vecKeys[idx]) ofSetColor(ofColor::green); else ofSetColor(ofColor::white); ofRect(0,0,9,30); ofTranslate(10,0); } } ofPopMatrix(); // Black Keys ofPushMatrix(); ofTranslate(5,0); for (int i=0;i<m_iNumOctaves;i++){ for(int j=0; j<5;j++){ idx = 12*i + 2*j+1; if (j>1) ++idx; if(j==2) ofTranslate(10,0); if (m_vecKeys[idx]) ofSetColor(ofColor::green); else ofSetColor(ofColor::black); ofRect(0,0,9,15); ofTranslate(10,0); } ofTranslate(10,0); } ofPopMatrix(); ofPushMatrix(); ofTranslate(0,40); // Mod ofSetColor(ofColor::black); ofRect(0,0,m_iNumOctaves*7*10,10); ofSetColor(ofColor::red); ofRect(0,0,ofMap(m_iMod,0,127,0,m_iNumOctaves*7*10),10); // Pitch ofTranslate(0,15); ofSetColor(ofColor::black); ofRect(0,0,m_iNumOctaves*7*10,10); ofSetColor(ofColor::red); ofRect(0,0,ofMap(m_iPitch,0,16384,0,m_iNumOctaves*7*10),10); // Program ofTranslate(0,30); ofSetColor(ofColor::white); ofDrawBitmapString(m_sText.str(),0,0); ofPopMatrix(); ofPushMatrix(); ofTranslate(300,-20); ofPushStyle(); ofFill(); // CutOff drawPotentiometer(ofMap(m_iCutOff,0,127,0,TWO_PI)); ofTranslate(40,0); // Resonance drawPotentiometer(ofMap(m_iResonance,0,127,0,TWO_PI)); ofTranslate(40,0); // Attack drawPotentiometer(ofMap(m_iAttack,0,127,0,TWO_PI)); ofTranslate(40,0); // Release drawPotentiometer(ofMap(m_iRelease,0,127,0,TWO_PI)); ofTranslate(40,0); // Tempo drawPotentiometer(ofMap(m_fTempo,20,300,0,TWO_PI)); ofTranslate(40,0); ofPopMatrix(); ofPopStyle(); ofPopStyle(); ofPopMatrix(); }
//-------------------------------------------------------------- void ofApp::update(){ // timer update timer.update(); // dmx if (enableDmx) { for (int i = 0; i < DMX_CHANNEL_NUMBER; i++) { dmxChannels[i].set(tween.update()); dmx.setLevel(i+1, dmxChannels[i]);// be careful, dmx channel starts from 1, not 0. } dmx.update(); if ((int)ofGetElapsedTimef() % DMX_TIMER_PER_SECONDS == 0){ // FIXME: hard code and use same tween to each dmx channel for (int i = 0; i < DMX_CHANNEL_NUMBER; i++) { doEase(dmxChannels[i], 10000, 0); } } } // kinect kinect.update(); if( kinect.isFrameNew() ){ if (showPanel) { texDepth.loadData(kinect.getDepthPixels()); texRGB.loadData(kinect.getRgbPixels()); } rawDepthPixels = kinect.getRawDepthPixels(); // bullet if (kinectBulletShape == NULL ) { updateKinectMesh(); setupWhenKinectIsReady(); }else if(enableScanPeople) { // scanning people feature if (!diffDepthTexture.isAllocated()) { diffDepthTexture.allocate(rawDepthPixels.getWidth(), rawDepthPixels.getHeight(), GL_RGB);// color texture diffDepthTexturePixels = new unsigned char[rawDepthPixels.getWidth()*rawDepthPixels.getHeight()*3]; } diffDepthPixels = rawDepthPixels; // copy float * diffDepthPixelsPointer = diffDepthPixels.getPixels(); modelStartPositions.clear(); for (int x = 0; x < rawDepthPixels.getWidth(); x++) { for (int y = 0; y < rawDepthPixels.getHeight(); y++) { diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] = savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x]-rawDepthPixels[rawDepthPixels.getWidth()*y+x]; if (/* savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x] > kinect.minDistance && savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x] < kinect.maxDistance && */ rawDepthPixels[rawDepthPixels.getWidth()*y+x] > kinect.minDistance && rawDepthPixels[rawDepthPixels.getWidth()*y+x] < kinect.maxDistance) { if (diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] > 0) { // calculate probability float probability = diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] / probabilityFactor; // judge add or not bool judgeAdd = (ofRandomuf() < probability); if (judgeAdd) { modelStartPositions.push_back(ofVec3f(x, y, modelStartPosition->z)); } // set diffDepthTexturePixels with red color if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = ofMap(diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x], 0, kinect.maxDistance-kinect.minDistance, 0, 255, true) ; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = 0; // b } }else{ // set diffDepthTexturePixels with blue color if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = 0; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = ofMap(-1*diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x], 0, kinect.maxDistance-kinect.minDistance, 0, 255, true); // b } } }else{ // black if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = 0; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = 0; // b } } } } // grayscale diff texture // diffDepthTexture.loadData(diffDepthPixels); // draw RGB diff texture if (showPanel) { diffDepthTexture.loadData(diffDepthTexturePixels, rawDepthPixels.getWidth(), rawDepthPixels.getHeight(), GL_RGB); } }else{ updateKinectMesh(); } } // bullet if (!stopUpdatingKinectBullet && !enableScanPeople) { if (kinectHeight != 0 && kinectBulletShape != NULL) { kinectBulletShape->remove(); kinectBulletShape->create( world.world, kinectMesh, ofVec3f(0,0,0), 0.f, ofVec3f(0, 0, 0), ofVec3f(kinectWidth, kinectHeight, kinect.maxDistance.getMax()) ); kinectBulletShape->add(); kinectBulletShape->enableKinematic(); kinectBulletShape->setActivationState( DISABLE_DEACTIVATION ); } } // model if (enableAddModel) { // add model in modelStartPosition ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(1., 0., 0., PI); int modelId = modelSetVector[bulletCustomShape->getSetId()][bulletCustomShape->getIndex()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); bulletCustomShape->create(world.world, modelStartPosition, startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*0.005); assimpModelBulletShapes.push_back(bulletCustomShape); } if (enableAddModelRandom && timer.getName() != "interval") { // add model in random x, random y and modelStartPosition.z ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1), ofRandom(-1*PI, PI)); int modelId = modelSetVector[bulletCustomShape->getSetId()][bulletCustomShape->getIndex()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); // random square // ofVec3f instantModelStartPosition(ofRandom(0, w), ofRandom(0, h), modelStartPosition->z); // random circle float instantRadius = ofRandom(0, 500); // float instantRadius = (ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500))/5.0; float instantTheta = ofRandom(-PI, PI); ofVec3f instantModelStartPosition(kinectWidth/2.0+instantRadius*cos(instantTheta), kinectHeight/2.0+instantRadius*sin(instantTheta), modelStartPosition->z); bulletCustomShape->create(world.world, instantModelStartPosition, startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*ofRandom(-0.01, 0.01)); ofVec3f instantTorque(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); bulletCustomShape->applyTorque(instantTorque); assimpModelBulletShapes.push_back(bulletCustomShape); } if (enableScanPeople) { // add models in modelStartPositioins // ofLogNotice("modelStartPositions"+ofToString(modelStartPositions.size())); for (int i = 0; i < modelStartPositions.size(); i++) { // add model in random x, random y and modelStartPosition.z ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1), ofRandom(-1*PI, PI)); int modelId = modelSetVector[currentModelSetId][rand()%(int)modelSetVector[currentModelSetId].size()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); bulletCustomShape->create(world.world, modelStartPositions[i], startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*ofRandom(-0.01, 0.01)); ofVec3f instantTorque; switch (currentModelSetId) { case 0: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 1: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 2: instantTorque.set(ofRandom(-0.0001, 0.0001), ofRandom(-0.0001, 0.0001), ofRandom(-0.0001, 0.0001)); break; case 3: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 4: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; default: break; } bulletCustomShape->applyTorque(instantTorque); assimpModelBulletShapes.push_back(bulletCustomShape); } } // world world.setGravity(worldGravity); world.update(ofGetLastFrameTime()*2, 20); ofRectangle kinectRange(0, 0, kinectWidth, kinectHeight); for( int i = 0; i < assimpModelBulletShapes.size(); i++ ) { // erase model which is in out range(z < 0) if(assimpModelBulletShapes[i]->getPosition().z < 0) { assimpModelBulletShapes[i]->remove(); assimpModelBulletShapes.erase(assimpModelBulletShapes.begin() + i); // erase only one bullet shape // break; }else if(kinectIsReady && kinectRange.inside(assimpModelBulletShapes[i]->getPosition().x, assimpModelBulletShapes[i]->getPosition().y)){ // apply force to bullet shape inside the float instantKinectDepth = rawDepthPixels[(int)assimpModelBulletShapes[i]->getPosition().x + (int)assimpModelBulletShapes[i]->getPosition().y*kinectWidth]; if (instantKinectDepth > kinect.minDistance && instantKinectDepth < kinect.maxDistance && assimpModelBulletShapes[i]->getPosition().z > instantKinectDepth) { // add force to the model which is above the kinect mesh if (ofGetMousePressed()) { ofVec3f wind(0, 0, 0.001); // FIXME: hard code assimpModelBulletShapes[i]->applyCentralForce(wind); } } } } // camera if (enableMouseInput) { camera.enableMouseInput(); }else{ camera.disableMouseInput(); camera.setupPerspective(false, cameraFov, cameraNearDist, cameraFarDist, ofVec2f(0.0f, 0.0f)); camera.setPosition(cameraPosition); camera.lookAt(ofVec3f(cameraLookAt), ofVec3f(0, -1, 0)); } // camera target debugSphereCameraTarget.setPosition(cameraLookAt); // light light.setPosition(lightPosition); light.setSpecularColor(lightSpecularColor); light.setDiffuseColor(lightDissuseColor); light.setAmbientColor(lightAmbientColor); light.setAttenuation(lightAttenuation->x, lightAttenuation->y, lightAttenuation->z); // material material.setSpecularColor(materialSpecularColor); material.setDiffuseColor(materialDiffuseColor); material.setAmbientColor(materialAmbientColor); material.setEmissiveColor(materialEmissiveColor); material.setShininess(materialShininess); }
//-------------------------------------------------------------- void testApp::update(){ ofSoundUpdate(); //SpaceShip if(shipMoveForward){ shipForce+=0.001; if(shipForce>=0.05){ shipForce=0.05; } } if(shipMoveBack){ shipForce-=0.001; if(shipForce<=0.002){ shipForce=-0.002; } } if (shipRotateLeft) { shipAngle+=3; } if (shipRotateRight) { shipAngle-=3; } shipFrcX= cos(ofDegToRad(shipAngle))*shipForce; shipFrcY= sin(ofDegToRad(shipAngle))*shipForce; ship.alpha = shipForce; ship.angle = shipAngle; ship.resetForce(); ship.addForce(shipFrcX, shipFrcY); ship.addDampingForce(); ship.moveOffWalls(); ship.update(); orginPos.x += ship.vel.x; orginPos.y += ship.vel.y; ship._posx = orginPos.x; ship._posy = orginPos.y; ship.bounceOffWalls(); cout<<ship.vel<<endl; //Goal for (int i = 0; i < goals.size(); i++){ goals[i]->resetForce(); goals[i]->addForce(0, 0); goals[i]->addDampingForce(); goals[i]->update(); goals[i]->pos-=ship.vel*2; ofPoint terminal; terminal = goals[i]->pos-ship.pos; if (terminal.length()<30) { score+=1; // goals[i]->setInitialCondition(ofRandom(-ofGetWidth(),ofGetWidth()*2),ofRandom(-ofGetWidth(), ofGetWidth()*2),0,0); goals.erase(goals.begin()+i); shipRadiance+=10; if(shipRadiance>=300){ shipRadiance=300; } } } //bg bgPos-=ship.vel/4; // particle sort( myParticles.begin(), myParticles.end(), comparisonFunction ); // sort them! for (int i = 0; i < myParticles.size(); i++){ myParticles[i]->resetForce(); myParticles[i]->radius = shipRadiance; } for (int i = 0; i < myParticles.size(); i++){ for (int j = i-1; j >= 0; j--){ if ( fabs(myParticles[j]->pos.x - myParticles[i]->pos.x) > 30) break; float speed; speed = ofMap(myParticles[i]->scale, 0, myParticles[i]->scale+myParticles[j]->scale, 0, 2.4f); myParticles[i]->addRepulsionForce( *myParticles[j],20,speed); } } for (int i = 0; i < myParticles.size(); i++){ for (int j = 0; j < goals.size(); j++){ myParticles[i]->addRepulsionForce(goals[j]->pos.x,goals[j]->pos.y,70,0.02f); } } float diffTime2 = ofGetElapsedTimeMillis()- firstTime; for (int i = 0; i < myParticles.size(); i++){ myParticles[i]->addForce(0,0); myParticles[i]->addAttractionForce(ship.pos.x,ship.pos.y,shipRadiance*myParticles[i]->scale,0.02f/myParticles[i]->scale); if (diffTime2<1000) { myParticles[i]->addRepulsionForce(ship.pos.x, ship.pos.y, 200, 0.2f); } myParticles[i]->addDampingForce(); myParticles[i]->update(); myParticles[i]->pos.x-=ship.vel.x*2; myParticles[i]->pos.y-=ship.vel.y*2; ofPoint dis; dis = ship.pos - myParticles[i]->pos; if (dis.length()<23+(myParticles[i]->asteroid->width/6*myParticles[i]->scale)) { orginPos.set(0, 0); shipExplode = true; ship.setInitialCondition(ofGetWidth()/2, ofGetHeight()/2, 0, 0); firstTime = ofGetElapsedTimeMillis(); score =0; shipRadiance = 30; myParticles.clear(); 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; } goals.clear(); 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)]; } bgPos.set(0, 0); shield =3; } } }
//-------------------------------------------------------------- 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(); ofVertices(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 testApp::update(){ for ( int i=0; i < 30; i ++){ if(i<5){ float sinOfTime = sin(ofGetElapsedTimef() * (0.3)); //for the speed of on/off float sinOfTimeMapped = ofMap(sinOfTime, -1, 1, 0, 255); ofEnableAlphaBlending(); //para cambiar la transparencia myCircle[i].color = (255, 250, 205, sinOfTimeMapped); //initial color amarillo un poco if(sinOfTimeMapped <= 50){ myCircle[i].x = ofRandom(ofGetWindowWidth()); myCircle[i].y = ofRandom(ofGetWindowHeight()); } else{ // // myCircle[i].y --; // myCircle[i].x ++; } if(myCircle[i].x > ofGetWindowWidth() || myCircle[i].x < 0) { myCircle[i].x = ofRandom(ofGetWindowWidth()); } if( myCircle[i].y > ofGetWindowHeight() || myCircle[i].y < 0) { myCircle[i].y = ofRandom(ofGetWindowHeight()); } } else { float sinOfTime = sin( ofGetElapsedTimef() * (i/3)); //sino es muy rapido el cambio float sinOfTimeMapped = ofMap( sinOfTime, -1, 1, 0, 255); ofEnableAlphaBlending(); //para cambiar la transparencia myCircle[i].color = (255, 250, 205, sinOfTimeMapped); //initial color amarillo un poco if(sinOfTimeMapped == 0){ myCircle[i].x = ofRandom(ofGetWindowWidth()); myCircle[i].y = ofRandom(ofGetWindowHeight()); } else{ // myCircle[i].y --; // myCircle[i].x ++; } if( myCircle[i].x > ofGetWindowWidth() || myCircle[i].x < 0) { myCircle[i].x = ofRandom(ofGetWindowWidth()); } if( myCircle[i].y > ofGetWindowHeight() || myCircle[i].y < 0) { myCircle[i].y = ofRandom(ofGetWindowHeight()); } } } }
void StISFNoiseFlower::update(){ isf->setUniform<float>("zoom", ofMap(app->p1, 0.0, 1.0, 0.1, 1.0)); isf->update(); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetVerticalSync(true); ofEnableAntiAliasing(); glEnable(GL_POINT_SMOOTH); // use circular points instead of square points glPointSize(3); // // --- Loading files ofFileDialogResult openFileResult = ofSystemLoadDialog("Get the txt data", true); ofLogNotice() << "Folder: " << openFileResult.getPath(); ofDirectory dirFiles; dirFiles.listDir( openFileResult.getPath() ); ofDrawBitmapString("Loading files", ofGetWidth()/2 - 20, ofGetHeight() / 2 ); for ( int indexOfFile = 0; indexOfFile < dirFiles.size(); ++indexOfFile ) { // ofLogNotice() << "file: " << dirFiles.getPath( indexOfFile ); ofBuffer buffer = ofBufferFromFile( dirFiles.getPath( indexOfFile ) ); std::vector< weatherData > currentWeatherData; if(buffer.size()) { buffer.getNextLine(); while(buffer.isLastLine() == false) { string line = buffer.getNextLine(); std::stringstream lineStream( line ); string cell; std::getline( lineStream, cell, ';' ); weatherData data; std::getline( lineStream, cell, ';' ); data.lon = ofToDouble( cell ); std::getline( lineStream, cell, ';' ); data.lat = ofToDouble( cell ); std::getline( lineStream, cell, ';' ); data.temp = ofToDouble( cell ); std::getline( lineStream, cell, ';' ); data.velWind = ofToDouble( cell ); currentWeatherData.push_back( data ); // std::cout << data.lon << "\t" << data.lat << "\t" << data.temp << "\n"; } } weatherTimed.weatherDataVector.push_back( currentWeatherData ); // --- transform into pixel vec ofMesh currentMeshTemp, currentMeshWind; currentMeshTemp.setMode(OF_PRIMITIVE_POINTS); currentMeshWind.setMode(OF_PRIMITIVE_POINTS); for ( auto &data : weatherTimed.weatherDataVector[ indexOfFile ] ) { data.point = ofVec3f( ofMap( data.lon, 0, 357, 0, 300 ), ofMap( data.lat, 32, 77, 0, 100), ofMap( data.temp, 273, 320, 0, 100 ) ); currentMeshTemp.addColor( ofColor(ofMap( data.temp, 273, 320, 0, 255, true ), 0, 0 ) ); currentMeshTemp.addVertex( data.point ); currentMeshWind.addColor( ofColor( 0, 0, ofMap( std::abs( data.velWind ), 0, 45, 0, 255, true ) ) ); currentMeshWind.addVertex( ofVec3f( ofMap( data.lon, 0, 357, 0, 300 ), ofMap( data.lat, 32, 77, 0, 100), ofMap( data.velWind, -55, 55, -100, 100 ) ) ); } weatherTimed.meshVecTemp.push_back( currentMeshTemp ); weatherTimed.meshVecWind.push_back( currentMeshWind ); } ofLogNotice() << "Loaded file amount: " << weatherTimed.meshVecTemp.size(); tempButton.addListener( this, &ofApp::tempPlotActivation ); windButton.addListener( this, &ofApp::windPlotActivation ); gui.setup(); gui.add( tempButton.setup( "Temperature Plot", true ) ); gui.add( windButton.setup("Wind Velocity Plot", false ) ); gui.add( timeSlider.setup("time", 0, 0, weatherTimed.meshVecTemp.size() - 1 ) ); gui.add( playButton.setup("play time", false ) ); gui.add( rotation.setup( "rotation", 0, 0, 360 ) ); gui.add( autoRotate.setup("Auto Rotate", true ) ); cam.disableMouseInput(); rotation = 0.0; tempPlotActivation(); picturePlot.loadImage("Plot1.png"); }
void Heiroglyphs::draw(){ if(!isCleanup) { fbo.begin(); ofPushMatrix(); ofPushStyle(); ofClear(0); ofPushStyle(); //ofSetColor(theme->color1); // ofRect(0,0,ofGetWidth(),ofGetHeight()); ofPopStyle(); if(audio->getAvgBin(0) - lastAmp > 1) { screenToggle = !screenToggle; } if(audio->getAvgBin(0) - lastAmp > 0.4) { heiroNumber = floor(ofRandom(0,4)); } ofPushStyle(); ofSetColor(255,255,255,ofMap(audio->getAvgBin(0),0,5,0,255)); if(screenToggle) { testScreenOne.draw(0,0,ofGetWidth(),ofGetHeight()); }else{ testScreenTwo.draw(0,0,ofGetWidth(),ofGetHeight()); } ofPopStyle(); ofPushStyle(); ofSetColor(255,255,255,audio->getAvgBin(3)*25 + 200); //heiros switch(heiroNumber) { case 0: heiro.drawSubsection(ofGetWidth()/2 - 800,ofGetHeight()/4,400,ofGetHeight()/2,0,0,400,540); heiro.drawSubsection(ofGetWidth()/2 - 400,ofGetHeight()/4,400,ofGetHeight()/2,0,0,400,540); heiro.drawSubsection(ofGetWidth()/2,ofGetHeight()/4,400,ofGetHeight()/2,0,0,400,540); heiro.drawSubsection(ofGetWidth()/2 + 400,ofGetHeight()/4,400,ofGetHeight()/2,0,0,400,540); break; case 1: heiro.drawSubsection(ofGetWidth()/2 - 800,ofGetHeight()/4,400,ofGetHeight()/2,400,0,400,540); heiro.drawSubsection(ofGetWidth()/2 - 400,ofGetHeight()/4,400,ofGetHeight()/2,400,0,400,540); heiro.drawSubsection(ofGetWidth()/2, ofGetHeight()/4,400,ofGetHeight()/2,400,0,400,540); heiro.drawSubsection(ofGetWidth()/2 + 400,ofGetHeight()/4,400,ofGetHeight()/2,400,0,400,540); break; case 2: heiro.drawSubsection(ofGetWidth()/2 - 800,ofGetHeight()/4,400,ofGetHeight()/2,800,0,400,540); heiro.drawSubsection(ofGetWidth()/2 - 400,ofGetHeight()/4,400,ofGetHeight()/2,800,0,400,540); heiro.drawSubsection(ofGetWidth()/2,ofGetHeight()/4,400,ofGetHeight()/2,800,0,400,540); heiro.drawSubsection(ofGetWidth()/2 + 400,ofGetHeight()/4,400,ofGetHeight()/2,800,0,400,540); break; case 3: heiro.drawSubsection(ofGetWidth()/2 - 800,ofGetHeight()/4,400,ofGetHeight()/2,1200,0,400,540); heiro.drawSubsection(ofGetWidth()/2 - 400,ofGetHeight()/4,400,ofGetHeight()/2,1200,0,400,540); heiro.drawSubsection(ofGetWidth()/2,ofGetHeight()/4,400,ofGetHeight()/2,1200,0,400,540); heiro.drawSubsection(ofGetWidth()/2 + 400,ofGetHeight()/4,400,ofGetHeight()/2,1200,0,400,540); break; default: break; } ofPopStyle(); lastAmp = audio->getAvgBin(0); scan.draw(); ofPopStyle(); ofPopMatrix(); fbo.end(); abr.begin(); abrFbo.begin(); abr.setUniform1f("amount", audio->getAvgBin(5)*50); abr.setUniform1f("intensity", ofMap(audio->getAmp(),0,8,0.1,0.3)); fbo.draw(0,0,ofGetWidth(),ofGetHeight()); abrFbo.end(); abr.end(); bulge.begin(); bulge.setUniform1f("width", ofGetWidth()/2); bulge.setUniform1f("height", ofGetHeight()/2); bulge.setUniform1f("radius", (ofMap(audio->getAvgBin(0),0,10,1.0,-0.2))*intro); fbo.draw(0,0,ofGetWidth(),ofGetHeight()); abrFbo.draw(0,0); bulge.end(); } if(isOutro) { intro-= 0.1f; if(intro <= 0.1) { isCleanup = true; } }else{ if(intro < 1.0) { intro += 0.1; }else{ intro = 1.0; } } age += 0.6; }
//-------------------------------------------------------------- void GrainPlayer::setPitchRandom(float _val){ grainPitch = pitch * (ofRandom(0.0, ofMap(_val, 0.0, 1.0, 0.0, 4.0))+1); }
//-------------------------------------------------------------- void testApp::update() { pd.sendFloat("tempo", ofMap(ofGetMouseX(), 0, ofGetWidth(), 300, 50)); }
//-------------------------------------------------------------- void testApp::draw() { if(count++>360) count=0;; ofRectangle drawRect((ofGetWidth()-sqWid)/2,yOffset,sqWid,sqWid); ofSetColor(175,175,175); background.draw(0, 0,width,height); int xint=ofMap(xpos, 0, maxValue.x-minValue.x, (width-sqWid)/2, (width+sqWid)/2,true); int yint=ofMap((maxValue.y-minValue.y)-ypos, 0, maxValue.y-minValue.y, yOffset, yOffset+sqWid,true); ofSetShadowDarkness( .5), ofShadowRounded((width-sqWid)/2-5, yOffset, sqWid+5, sqWid+5, 20); ofSetColor(255, 255, 255); ofRect((width-sqWid)/2-5, yOffset, sqWid+5, sqWid+5); net.draw(); ofSetColor(255, 255, 255); for (int i=0; i<numOctaves+1; i++) { ofPoint k=net.vertex(0, i); char num[32]; sprintf(num, "%i",i); arialLabel.drawString(num, k.x-30, k.y+arialLabel.stringHeight(num)/2); } for (int i=1; i<numOctaves+1; i++) { ofPoint k=net.vertex(i, 0); char num[32]; sprintf(num, "%i",i); arialLabel.drawString(num, k.x-arialLabel.stringWidth(num)/2, k.y+arialLabel.stringHeight(num)+7); } /************************** Reporting data ******************** ofSetColor(0xFFFFFF); char reportString[255]; sprintf(reportString, "nread = %i", nBytesRead); if (!bNoise) sprintf(reportString, "%s (%fhz)", reportString, targetFrequency); ofDrawBitmapString(reportString,80,380); //arialHeader.drawString(reportString,20, height-50); **************************************************************/ overlays(xint,yint); xMet.draw(((width-sqWid)/2-xMet.w)/2,ofGetHeight()/2); yMet.draw((width+sqWid)/2+((ofGetWidth()-(width+sqWid)/2)-yMet.w)/2,ofGetHeight()/2); ofSetLineWidth(6); ofEnableSmoothing(); for (unsigned int i=1; i<lines.size(); i++) { ofSetColor(65, 134, 200,255-i); ofLine(lines[i-1].x, lines[i-1].y, lines[i].x, lines[i].y); } ofDisableSmoothing(); frets((width-sqWid)/2, yOffset, sqWid, numOctaves, xint, yint); ofSetColor(65, 134, 200); ofCircle(xint, yint, 7); lines.push_front(ofPoint(xint,yint)); if (lines.size()>255) { lines.pop_back(); } if (overlayCnt==4) { reducedRatios(xint, yint); } if(newTimer>ofGetElapsedTimeMillis()) { int mW=ofGetWidth(); int mH=ofGetHeight(); string rep=\ "Trace the lines using the sliders.\n\ Press the New Activities button to access\n\ more screens.\n\ \n\ Trazar las lineas con los reguladores.\n\ Pulse el boton de Nuevas Actividades para acceder\n\ a mas pantallas."; ofRectangle s=arialLabel.getBoundingBox(rep, 0, 0); ofSetColor(64, 64,64); ofRoundedRect((mW-(s.width+40))/2, (mH-(s.height+40))/2, s.width+40, 40+s.height, 20); ofSetColor(255, 255, 255); arialLabel.drawString(rep, (mW-s.width)/2, (mH-s.height)/2+20); } if (calib) { ofSetColor(0,0,0,128); ofRect(0,0,ofGetWidth(),ofGetHeight()); ofSetColor(128, 128, 128); ofRoundedRect(150, 100, ofGetWidth()-300, ofGetHeight()-200, 20); char freq[32]; sprintf(freq, "%f",ypos+minValue.y); char reportString[255]; sprintf(reportString, "<-- yslider xslider -->"); int w= arialHeader.stringWidth(reportString); int h= arialHeader.stringHeight(reportString); ofSetColor(255, 255, 255); arialHeader.drawString(reportString,(width-w)/2, ofGetHeight()/4*2); arialHeader.drawString(freq,200, ofGetHeight()/4*2); sprintf(freq, "%f",xpos+minValue.x); arialHeader.drawString(freq,ofGetWidth()-(200+arialHeader.stringWidth(freq)), ofGetHeight()/4*2); sprintf(freq, "%f",ypos); sprintf(reportString, "<-- yoff from calibrated values xoff -->"); w= arialHeader.stringWidth(reportString); h= arialHeader.stringHeight(reportString); ofSetColor(255, 255, 255); arialHeader.drawString(reportString,(width-w)/2, ofGetHeight()/4*3); arialHeader.drawString(freq,200, ofGetHeight()/4*3); sprintf(freq, "%f",xpos); arialHeader.drawString(freq,ofGetWidth()-(200+arialHeader.stringWidth(freq)), ofGetHeight()/4*3); if(maxValue.x<1024&&maxValue.y<1024) { sprintf(reportString, "To re-calibrate, pull back sliders and press 'r'."); w= arialHeader.stringWidth(reportString); h= arialHeader.stringHeight(reportString); ofSetColor(255, 255, 255); arialHeader.drawString(reportString,(width-w)/2, ofGetHeight()/4); } else { sprintf(reportString, "Out of calibration range; tune with screwdriver."); w= arialHeader.stringWidth(reportString); h= arialHeader.stringHeight(reportString); ofSetColor(255, 255, 255); arialHeader.drawString(reportString,(width-w)/2, ofGetHeight()/4); } } }