//----------------------------------------------------------------------------------------- // void ofApp::update() { float time = ofGetElapsedTimef(); // time is equal to the amount of time passed // changes the vertices for each mesh at j for(int j=0; j<number; j++) { for(int y=0; y<h; y++) { for(int x=0; x<w; x++) { // vertex index int i = x + w * y; ofPoint pt = mesh[j].getVertex(i); float noise = ofNoise(x, y, time * 0.5); // Perlin noise value float rNoise = ofSignedNoise(x*0.5, y*0.3, time*0.1); // Creates a Perlin signed noise value for the red value of the mesh color // comment above line and uncomment line below for a variation of blue, purple, and red colors // float rNoise = ofSignedNoise(x*0.5, y*0.3, time); float bNoise = ofSignedNoise(x*0.5, y*0.3, time*0.1); // creates a Perlin signed noise value for the blue value of the mesh pt.z = noise ; // assigns noise to the z value so the noise affects the z space of the mesh mesh[j].setVertex(i, pt); mesh[j].setColor(i, ofColor(250*rNoise, 0, 250*bNoise)); // sets color of mesh // note: only using red and blue to make a purple color, then adding the rNoise and bNoise to change the values of red and blue to make different shades of purple } } setNormals(mesh[j]); // updates the normals for each mesh at j } }
void GTess::draw(){; float speedV = ofMap(speed, 0, 1, -2, 2); ofSetLineWidth(4); // waves going across red for(int i =0; i<mapping->triangles.size();i++) { ofSetColor( 255, 255, 255, ofNoise(mapping->triangles[i]->centroid.y/600 - ofGetElapsedTimef()/speed)*255); //mapping->triangles[i]-> ofSetColor( 255, 255, 255, ofNoise(mapping->triangles[i]->centroid.x/600 - ofGetElapsedTimef()/speed) *255 ); mapping->triangles[i]->mesh.drawWireframe(); } }
void StFftDistort::update(){ ofxUISlider *gnoisescale = (ofxUISlider *)gui->getWidget("NOISE SCALE"); float noisescale = gnoisescale->getValue(); ofxUISlider *gshiftspeed = (ofxUISlider *)gui->getWidget("SHIFT SPEED"); float shiftspeed = gshiftspeed->getValue(); float distortionStrength = ofMap(app->oscControl->controlVal[4], 0, 127, 1, 8); float fftSum = 0; for (int i = 0; i < app->fft->drawBins.size(); i++) { fftSum += app->fft->drawBins[i]; } int i = 0; for(int y = 1; y + 1 < ySteps; y++) { for(int x = 1; x + 1 < xSteps; x++) { int i = y * xSteps + x; float noiseX = ofMap(currentVertex[i].x, 0, ofGetWidth(), 0, noisescale); float noiseY = ofMap(currentVertex[i].y, 0, ofGetWidth(), 0, noisescale); float offset = ofNoise(noiseX + ofGetElapsedTimef() * shiftspeed, noiseY + ofGetElapsedTimef() * shiftspeed); currentVertex[i].z = offset * distortionStrength * fftSum; mesh.setVertex(i, currentVertex[i]); i++; } } gui->setVisible(getSharedData().guiVisible); }
//-------------------------------------------------------------- void ofApp::update(){ wind[0] = ofNoise(wind[0])/100 * -1; applyForce(wind); // bounce from top if (loc[1] < 59) { loc[1] = 60; vel[1] = 0; applyForce(ceiling); } else if (loc[0] < 60) { loc[0] = 60; } vel += acc; loc += vel; acc.scale(0); // arduino // receive and analyse data in an infinite while loop while (true) { int c = serial.readByte(); // break the loop if all data received by the serial port was already processed or there is an error if (c == OF_SERIAL_NO_DATA || c == OF_SERIAL_ERROR || c == 0) break; // if a new line symbol is received, set a value to the arduinoSpeed variable // clear the buffer to be ready to receive the next value if (c == '\n') { arduinoSpeed = ofToFloat(str); str = ""; } // append the received value to the buffer else str.push_back(c); } }
void Drop::draw(){ ofPushMatrix(); ofTranslate(pos); ofBeginShape(); for (int i = 0; i < 200; i++){ float add = ofNoise(i/20.0f, noiseOffset * 3 * dropNoiseLevel / (float)ofGetWidth()); dropRadius = dropRadiusDefault * noiseOffset; ofSetColor(c, trans); ofVertex((dropRadius + 5 * add * noiseOffsetOutline) * cos((i/200.0)*TWO_PI), (dropRadius + 5 * add * noiseOffsetOutline) * sin((i/200.0)*TWO_PI)); } ofEndShape(); ofPopMatrix(); }
void Particle::update(){ // noiseFloat = ofNoise(pos.x * 0.0025, pos.y * 0.0025, ofGetElapsedTimef() * 0.001); // noiseVec.x = cos(((noiseFloat -0.3) * TWO_PI) * 10); // noiseVec.y = sin(((noiseFloat - 0.3) * TWO_PI) * 10); //cout<<noiseVec<<endl; noiseFloat = ofNoise(pos.x * *xNoiseValue, pos.y * *yNoiseValue, ofGetElapsedTimef() * *zNoiseValue); noiseVec.x = cos(((noiseFloat -0.3) * TWO_PI + *xAngleOffset) * *xNoiseScale); noiseVec.y = sin(((noiseFloat - 0.3) * TWO_PI + *yAngleOffset) * *yNoiseScale); vel += noiseVec; vel *=0.8; pos += vel; if(1.0-(age/lifeTime) == 0){ isDead = true; } if(pos.x < 0 || pos.x > ofGetWindowWidth() || pos.y < 0 || pos.y > ofGetWindowHeight()){ isDead = true; } age++; }
//-------------------------------------------------------------- void testApp::updateSpotFromMoversGaussian(){ float interval = ofGetWidth()/nbLedProjector; for (int i = 0; i < (int) movers.size(); i++){ float diameter = movers[i].get()->getDiameter(); float radius = diameter/2.; float where = (movers[i].get()->getLocation().x-radius)/interval; float gaussian_intensity = ofMap(movers[i].get()->getVelocity().length(),0,6,gaussian_intensity_min, gaussian_intensity_max,true); gaussian_intensity *= movers[i].get()->getLightning(); float sd = ofMap(movers[i].get()->getDiameter(),2.7,40,sd_min,sd_max,false); /* for (int i = 0; i < nbLedProjector; i++){ float value = gaussian(i, where, sd)*gaussian_intensity/100; spots[i]+=value; } */ // add perlin noise on the gaussian movers[i].get()->yoff += yoff_inc; float xoff = 0; for (int k = 0; k < nbLedProjector; k++){ xoff += xoff_inc; float value = gaussian(k, where, sd)*gaussian_intensity/100; float perlin = ofNoise(xoff, movers[i].get()->yoff)*tourbillons_intensite/100; value += (perlin-0.5)*value; spots[k]+=value; } } }
void Enemy::branch( float length, float _ang1, float _ang2, float _mult, bool _trans ) { // Matt--this is copied and heavily modified from Charlie's in-class example. if ( _trans ) { ofTranslate( 100, 0 ); } ofPushMatrix(); ofLine( ofVec2f(0,0), ofVec2f(0, -length) ); ofTranslate( 0, -length ); // generation++; float noise = ofNoise(ofGetElapsedTimef() * 0.1 ); if( length > 2 ){ ofPushMatrix();{ ofRotate( ( _ang1 + theta + noise * 10-5 ) * _mult ); branch( length * 0.666, _ang1, _ang2, _mult, _trans ); }ofPopMatrix(); ofPushMatrix();{ ofRotate( ( _ang2 + theta - noise * 10-5 ) * _mult ); branch( length * 0.666, _ang1, _ang2, _mult, _trans ); }ofPopMatrix(); } ofPopMatrix(); // generation--; }
//-------------------------------------------------------------- void testApp::update(){ ofSetWindowTitle(ofToString(ofGetFrameRate())); unsigned char* pixels = myPerlin.getPixels(); for (int i=0; i<640; i++) { for (int j = 0; j <480; j++) { pixels[j*640+i]= ofNoise(i*0.005+mouse.x,j*0.005+mouse.y, ofGetElapsedTimef())*150; }} for (int j=0; j<100; j++) { ofSetColor(255 * ofNoise(j * 0.01, j, mouseY * 20, 1), 255 * ofNoise(j * 0.01, j, mouseY * 20, 2), 255 * ofNoise(j * 0.01, j, mouseY* 20, 3)); myPerlin.update(); } }
//-------------------------------------------------------------- void testApp::draw(){ // for(int i=0; i<10; i++){ // for(int j=0; j<10; j++){ // ofSetColor(ofRandom(255), ofRandom(255), ofRandom(255)); // ofRect(i*10,j*10,10,10); // } // } for(int i=0; i<100; i++){ for(int j=0; j<100; j++){ ofSetColor(255* ofNoise(i,j, mouseY * 0.001, 1), 255* ofNoise(i,j, mouseY * 0.001, 2), 255* ofNoise(i,j, mouseY * 0.001, 3)); //ofNoise(x,y,z,w); ofRect(i * 10,j * 10,10,10); } } }
void StFftSphereRibbon::update(){ ofxUISlider *gnoisescale = (ofxUISlider *)gui->getWidget("NOISE SCALE"); float noisescale = gnoisescale->getValue(); ofxUISlider *gshiftspeed = (ofxUISlider *)gui->getWidget("SHIFT SPEED"); float shiftspeed = gshiftspeed->getValue(); ofxUISlider *ginterp = (ofxUISlider *)gui->getWidget("INTERPORATION"); float interp = ginterp->getValue(); ofxUISlider *gthickness = (ofxUISlider *)gui->getWidget("RIBBON WIDTH"); float thickness = gthickness->getValue(); float distortionStrength = ofMap(app->oscControl->controlVal[4], 0, 127, 2, 10); float fftSum = 0; for (int i = 0; i < app->fft->drawBins.size(); i++) { fftSum += app->fft->drawBins[i]; } for (int i = 0; i < mesh.getVertices().size(); i++) { float noiseX = ofMap(currentVertex[i].x, 0, ofGetWidth(), 0, noisescale); float noiseY = ofMap(currentVertex[i].y, 0, ofGetWidth(), 0, noisescale); float noiseZ = ofMap(currentVertex[i].y, 0, ofGetWidth(), 0, noisescale); float offset = ofNoise(noiseX + ofGetElapsedTimef() * shiftspeed, noiseY + ofGetElapsedTimef() * shiftspeed); currentVertex[i] = currentVertex[i].normalize() * (offset * fftSum * distortionStrength); float randStrength = distortionStrength * 5.0; currentVertex[i] += ofVec3f(ofRandom(-randStrength, randStrength), ofRandom(-randStrength, randStrength), ofRandom(-randStrength, randStrength)); mesh.setVertex(i, currentVertex[i]); interplateVertex[i] += (currentVertex[i] - interplateVertex[i]) * interp; ribbons[i]->thickness = thickness; ribbons[i]->update(interplateVertex[i]); } gui->setVisible(getSharedData().guiVisible); }
void wCity::update(){ ofPoint pos = *this*ofGetElapsedTimef()*0.001; if ( noisePeaks != NULL){ if ( *noisePeaks > 0.0){ noise = powf( *noisePeaks ,ofNoise( sin(pos.x),pos.y,pos.z*0.1)); nNoise = ofMap(noise,0.001,*noisePeaks,0.0,1.0,true); color.setHue( 20+nNoise*30 ); size = nNoise*5.0; } } else { float blink = abs(sin(ofGetElapsedTimef()*freq)); color.setHue( 20+ blink * 30 ); size = blink * 2.0; } if (noiseThreshold != NULL && noisePeaks != NULL){ if (nNoise > *noiseThreshold ){ if (!bRipple && *noisePeaks > 0.0) bRipple = true; } } if (bRipple){ if (ripplePct<1.0){ ripplePct += 0.01; } else { ripplePct = 0.0; bRipple = false; } } }
//-------------------------------------------------------------- void ofApp::drawLinePixel(float X1, float Y1,float X2, float Y2, float linewidth,ofColor col){ float t; pointX,pointY = 0; // if slope does not exsists if ( X1 == X2) { pointX = X1; for ( t = 0; t <= Y2; t++) { pointY = pointY + Y1; // ofSetColor(0); // ofPoint(t,pointY); ofSetColor(mycolor); ofCircle(pointX, pointY,linewidth ); } } // the slope exsist else { float slopeK = ( Y2 - Y1 ) / ( X2- X1 );//calculate the slope for ( t = X1; t <= X2; t++) { pointX = t; pointY = slopeK * (t - X1) + Y1; // ofSetColor(0); // drawImage1(X1, Y1, X2, Y2, 160, 200, 0); ofSetColor(mycolor); ofCircle(pointX, pointY,ofMap(ofNoise(t), X1, X2, 0.3, linewidth) ); // ofEllipse(pointX, pointY, ofMap(ofNoise(t+3), X1 , X2, 0.2, linewidth), ofMap(ofNoise(t), X1 , X2, 0.2, 23 * linewidth)); } } }
void testApp::newParticleField(int res){ int particleResolution = res; float randomScatter = 30; randomPerl = ofRandom(1000); float perlinScale = 0.005; for(int y = 0; y < ofGetWindowHeight(); y += particleResolution){ for(int x = ofGetWindowWidth()/2 - ofGetWindowHeight()/2; x < ofGetWindowWidth()/2 + ofGetWindowHeight()/2; x += particleResolution){ //calculate point distance from attractor float distSq = ofDistSquared(x, y, attractorPos.x, attractorPos.y); //create new points only if outside attractor if(distSq > (attractorSize + attractionRad) * (attractorSize + attractionRad)){ float noiseVal = ofNoise(x * perlinScale + randomPerl, y * perlinScale + randomPerl); if(noiseVal > 0.5){ Particle p; p.pos.set(x + ofRandom(-randomScatter, randomScatter), y + ofRandom(-randomScatter, randomScatter)); p.setup(&pImg); //add to x pos to center them in window // p.pos.x += ofGetWindowWidth()/2 - ofGetWindowHeight()/2; pList.push_back(p); } } } } }
void testApp::perlinBlob(int base, float range, int randSeed, int rot){ float speed = 0.2; float fringeWidth = base * range; ofPushMatrix();{ ofTranslate( ofGetWindowSize() / 2); ofRotate(rot); ofBeginShape(); for (int i = 0; i < 100; i++){ //Code borrowed from Charley Whitney (Algorithmic Animations Fall 2013) float add = ofNoise(i/20.0f, ofGetElapsedTimef() * speed + randSeed); //this will draw a circle with a min radius of the incoming value //plus the fringe value ofVertex( (base - fringeWidth * add) * cos((i/100.0)*TWO_PI), (base - fringeWidth * add) * sin((i/100.0)*TWO_PI)); } //ofVertex(firstX, firstY); ofEndShape(); }ofPopMatrix(); }
ofVec3f Surface::setNoiseHeight(ofVec3f temp){ float mult; float div; if (seed.getSurfaceType() == Seed::S_WATER){ mult = .1; div = .00454; } else { mult = .005; div = .002; } int xCoord = ofMap(temp.x, -seed.shapeSize/2, seed.shapeSize/2, 0, surfaceRes); int yCoord = ofMap(temp.y, -seed.shapeSize/2, seed.shapeSize/2, 0, surfaceRes); float a = xCoord * mult; float b = yCoord * mult; float c = surfaceID * div; float noise = ofNoise(a,b,c) * 255; float color = noise>75 ? ofMap(noise,75,255,0,255) : 0; return ofVec3f(temp.x, temp.y, color*surfaceHeightMult); }
//-------------------------------------------------------------- void testApp::updateMultibandNoiseDemo(){ // For each noise strip for (int i=0; i<nNoiseStrips; i++){ // Push the older data to the end of the array float *data = (float *)noiseDataStripGroup[i].data; for (int j=(NOISE_DATA_STRIP_LENGTH-1); j>0; j--){ data[j] = data[j-1]; } // Add the most recent data, the noise value. // Here's where we actually fetch the noise, using ofNoise(). // Note how ofNoise() requires an argument ('t'); this is // the coordinate (on a one-dimensional axis) whose // corresponding noise value we wish to obtain. //加入最近的数据,既噪点数值。 //这里是我们真正取得噪点的地方,使用ofNoise(). //注意如何使用ofNoise() 取得论据“(‘t‘); //这是相对应于我们希望取得的噪点数值的坐标(在一纬的轴上); float noiseStep = noiseDataStripGroup[i].noiseStep; float t = (ofGetElapsedTimeMillis()/10.0 + i) * noiseStep; data[0] = ofNoise(t); } // Compute the normalization factor: the total sum of the weights // for all of the contributing noise channels. This number is the largest // value which the sum of noise streams could possibly achieve. // 计算出一个标准化因子:所有噪点频道的总值的权重。这个数字是噪点可以取得的最大值 float normalizationFactor = 0; for (int i=0; i<nNoiseStrips; i++){ float weight = sliderGroup[i].getValue(); normalizationFactor += weight; } if (normalizationFactor == 0){ normalizationFactor = 1.0; } // For every sample in the recording history, // 为了每一个记录样本 for (int j=0; j<NOISE_DATA_STRIP_LENGTH; j++){ float sumj = 0; // Sum the weighted contribution from each of the noise strips. //相加每一个噪点条的权重 for (int i=0; i<nNoiseStrips; i++){ float val = noiseDataStripGroup[i].data[j]; float weight = sliderGroup[i].getValue(); sumj += (weight * val); } // Normalize it to the range 0...1 by dividing it // by normalizationFactor, as we discussed above. //标准化它的范围到0-1之间通过除以一个标准因子,也就是我们上面讨论的东西。 summedNoiseData[j] = sumj / normalizationFactor; } }
void ofApp::update() { filter.begin(); ofSetColor(255); ofTranslate(ofGetWidth() / 2, ofGetHeight() /2); ofRotate(ofGetElapsedTimef() * 20); int n = 13; for(int i = 0; i < n; i++) { float theta = ofMap(i, 0, n, 0, 360); ofPushMatrix(); ofRotate(theta); ofTranslate(50 + 150 * ofNoise(ofGetElapsedTimef() + i), 0); if(i% 6 < 3) { ofFill(); } else { ofNoFill(); } if(i % 2 == 0) { ofCircle(0, 0, 32); } else { ofRect(-16, -16, 32, 32); } ofPopMatrix(); } filter.end(); }
void ofApp::updateMesh(ofMesh* mesh, ofMesh* MeshOut) { for (int i=0; i<mesh->getNumVertices(); i++) { auto vertex = mesh->getVertex(i); auto normal = mesh->getNormal(i); // calc noise distortion auto noiseVert = vertex / noiseInDiv; if (isNoiseFromNormal) { // use normals noiseVert = MeshOut->getNormal(i) / noiseInDiv; // Sydney Opera House float scalar = i % noiseVertMod; noiseVert = ofVec3f(scalar, scalar, scalar) * noiseInDiv; } // simplex noise creates uneven shapes float noise = ofNoise(noiseVert.z*noiseIn.get().z, noiseVert.x*noiseIn.get().x, noiseVert.y*noiseIn.get().y) -0.5; // sin multiplier gives more even lumps //noise = sin(noiseVert.z*noiseIn.get().x) * sin(noiseVert.x*noiseIn.get().y) * sin(noiseVert.y*noiseIn.get().z); // cos multiplier gives more even lumps //noise = cos(noiseVert.z*noiseIn.get().x) * cos(noiseVert.x*noiseIn.get().y) * cos(noiseVert.y*noiseIn.get().z); // threshold for square shapes //if (noise > 0.2) noise = 0.5; //if (noise < -0.2) noise = -0.5; auto nextVertex = vertex += normal * (noise * noiseOutMult); auto lastVert = MeshOut->getVertex(i); vertex.x = ofLerp(lastVert.x, nextVertex.x, 0.1); vertex.y = ofLerp(lastVert.y, nextVertex.y, 0.1); vertex.z = ofLerp(lastVert.z, nextVertex.z, 0.1); // update vert MeshOut->setVertex(i, vertex); } }
void testApp::update() { vector<ofVec2f> touches; ofSeedRandom(0); for(int i = 0; i < 1; i++) { float f = .1; touches.push_back( ofVec2f( ofGetWidth() * ofNoise(ofGetElapsedTimef() * f + ofRandom(1024)), ofGetHeight() * ofNoise(ofGetElapsedTimef() * f + ofRandom(1024)))); } if(ofGetMousePressed()) { touches.push_back(ofVec2f(mouseX, mouseY)); } scenes[curScene]->setTouches(touches); scenes[curScene]->update(); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetCircleResolution(120); red = 233; blue = 233; green = 233; hideGUI = false; bdrawGrid = false; bdrawPadding = false; ddl = NULL; textInput = NULL; img = new ofImage(); img->loadImage("nerd_me.png"); buffer = new float[256]; for(int i = 0; i < 256; i++) { buffer[i] = ofNoise(i/100.0); } setGUI1(); setGUI2(); setGUI3(); setGUI4(); setGUI5(); gui1->loadSettings("gui1Settings.xml"); gui2->loadSettings("gui2Settings.xml"); gui3->loadSettings("gui3Settings.xml"); gui4->loadSettings("gui4Settings.xml"); gui5->loadSettings("gui5Settings.xml"); }
void Square::setup(){ _x = ofRandom(0, ofGetWidth()); _y = ofRandom(0, ofGetHeight()); // // float sinOfTime = sin( ofGetElapsedTimef() ); // float sinOfTimeMapped = ofMap(sinOfTime, -1, 1, 0, 500); // float sinOfTime2 = sin( ofGetElapsedTimef() + PI); // float sinOfTimeMapped2 = ofMap(sinOfTime2, -1, 1, 0, 500); // speedX = sinOfTimeMapped; // speedY = sinOfTimeMapped2; // speedX = (-2, 5); // speedY = (-2, 5); // float time = ofGetElapsedTimef(); // float cosOfTime = cos(time * 2.0) * 0.5; // float cosOfTime2 = cos(time) * 0.3; float value = ofNoise(0); // speedX = ofMap(cosOfTime, -1, 1, 0, ofGetWidth()); // speedY = ofMap(cosOfTime2, -1, 1, 0, ofGetHeight()); w = ofRandom(30, 80); h = ofRandom(10, 50); color.set(ofRandom(255),ofRandom(255),ofRandom(255)); }
void Meeba::drawMeebs() { meshTop.setMode(OF_PRIMITIVE_POINTS); for(float i=0; i <2*PI; i+=PI/density){ float a = cos(i); float b = sin(i); ofPoint pos; ofPoint negPos; float increment = 1; //float radiusSound = radius+sound.x ; float radius2 = radius + ofNoise(ofGetElapsedTimef(), i) * 50; for(float j=0; j<radius2+increment; j+=increment){ float x = a*j+ofGetWidth()/2 + shift.x; float y = b*j+ofGetHeight()/2 + shift.y; float z = abs(sqrt(radius2*radius2-(a*a*j*j + b*b*j*j))); //cout << negZ << endl; pos.set(x, y, z); negPos.set(x, y, -z); meshTop.addVertex(pos); meshTop.addColor(color); meshTop.addVertex(negPos); meshTop.addColor(color); } } meshTop.draw(); meshTop.clear(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofBackgroundGradient(130,20,OF_GRADIENT_CIRCULAR); ofSetCircleResolution(100); float angle = TWO_PI/numCircles; float sinValue = sin(ofGetElapsedTimef()/TWO_PI); float cosValue = cos(ofGetElapsedTimef()/TWO_PI); for (int i = 0; i < numCircles; i++){ float radius = ofNoise(ofGetElapsedTimef()+i*2)*500; float centerx = pos.x + radius*cos(angle*i); float centery = pos.y + radius*sin(angle*i); circles[i].draw(centerx, centery, 1+sinValue*100, i/numCircles); } }
//-------------------------------------------------------------- void testApp::update() { float t = (ofGetElapsedTimef()) * 0.9f; float div = 250.0; for (int i=0; i<NUM_BILLBOARDS; i++) { // noise ofVec3f vec(ofSignedNoise(t, billboardVerts[i].y/div, billboardVerts[i].z/div), ofSignedNoise(billboardVerts[i].x/div, t, billboardVerts[i].z/div), ofSignedNoise(billboardVerts[i].x/div, billboardVerts[i].y/div, t)); vec *= 10 * ofGetLastFrameTime(); billboardVels[i] += vec; billboardVerts[i] += billboardVels[i]; billboardVels[i] *= 0.94f; billboardSize[i] = 12 + billboardSizeTarget[i] * ofNoise(t + i); } // move the camera around float mx = (float)mouseX/(float)ofGetWidth(); float my = (float)mouseY/(float)ofGetHeight(); ofVec3f des(mx * 360.0, my * 360.0, 0); cameraRotation += (des-cameraRotation) * 0.03; zoom += (zoomTarget - zoom) * 0.03; }
void branch::update(){ if (radius>=minRadius) { radius*=branchDecay; float theta = ofNoise(currentPos.x, currentPos.y, currentPos.z); theta*=2*PI; if (nodes.size() >20) { currentAcc = cos(theta)*nodes.back().u+radius*sin(theta)*nodes.back().u; } currentVel+=0.1*currentAcc; currentVel*=branchDecay; currentVel.limit(5); currentPos+=currentVel; //branchNode b = branchNode(nodeRes,radius+1.0*sin(age*2*PI/20),currentPos+ofxVec3f(ofRandom(-0.1, 0.1),ofRandom(-0.1, 0.1),ofRandom(-0.1, 0.1)),currentVel); branchNode b = branchNode(nodeRes,radius+0.4*radius*sin(age*2*PI/20),currentPos,currentVel); nodes.push_back(b); age++; } if (timeToStem()) { doStem(); } //Update Children childIter = children.begin(); while (childIter!=children.end()){ childIter->update(); ++childIter; } }
//-------------------------------------------------------------- //-------------------------------------------------------------- void testApp::setup(){ for (int i = 0; i < 100; i++){ float x = i; float y = ofNoise(1000 + i / 10.0) * 50; pts.push_back(ofPoint(x,y)); xVals.push_back(x); yVals.push_back(y); } /* SplineT::Debug(0); SplineT spline(&xVals[0], xVals.size(), &yVals[0], 0, 0, 12); printf("coefficients \n"); splineInfo info; for (int i = 0; i <= spline.M; i++){ printf("%i = %f \n", i, spline.coefficient(i)); info.coefficients.push_back(spline.coefficient(i)); info.M = spline.M; info.DX = spline.DX; info.xmin = spline.xmin; info.xmax = spline.xmax; info.mean = spline.mean; } for (int i = 0; i < 100; i++){ float y = evaluate(i, &info.coefficients[0], info.xmin, info.DX, info.M, info.mean); //evaluate(<#float x#>, <#float *coeficients#>, <#float xmin#>, <#float DX#>, <#int M#>, <#float mean#>) ptsResult.push_back(ofPoint(i,y)); } */ }
//-------------------------------------------------------------- void testApp::draw(){ // draw mouse circles to front canvas canvas[0].begin(); // fade out the bg a little ofSetColor(0,2); ofRect(0,0, canvas[0].getWidth(), canvas[0].getHeight()); ofSetColor(255); // draw a box outline ofNoFill(); ofSetLineWidth(5); ofRect(5,5, canvas[0].getWidth()-10, canvas[0].getHeight()-10); ofFill(); // draw some little circles ofCircle(mouseX, mouseY, ofRandom(5,10)); canvas[0].end(); // have the top of the box show random colors canvas[1].begin(); ofSetColor(ofNoise(ofGetElapsedTimef()) * 255.0f, ofNoise(ofGetElapsedTimef() * .5) * 255.0f, ofNoise(ofGetElapsedTimef() * .25) * 255.0f); ofRect(0,0, canvas[1].getWidth(), canvas[0].getHeight()); canvas[1].end(); // have the side of the box combine the two canvas[2].begin(); // draw somewhat transparent ofSetColor(255, 150); canvas[0].draw(0,0); canvas[1].draw(0,0); canvas[2].end(); // draw your mappers and canvases for (int i=0; i<3; i++){ mappers[i].startMapping(); canvas[i].draw(0,0); mappers[i].stopMapping(); if ( bDrawBounds ){ mappers[i].drawBoundingBox(); // some instructions! ofDrawBitmapString("press '1', '2', or '3' to just select one box at a time!\npress 's' to save", 20,20); } } }
//-------------------------------------------------------------- void testApp::renderNoisyRobotArmDemo(){ float t = ofGetElapsedTimef(); float shoulderNoiseAngleDegrees = 90 + 70.0 * ofSignedNoise(t * 1.00); float elbowNoiseAngleDegrees = 60 + 80.0 * ofSignedNoise(t * 0.87); float wristNoiseAngleDegrees = (2.5 * 72) + 45.0 * ofSignedNoise(t * 1.13); float noisyR = ofNoise(t * 0.66); // different multiplicative step-factors float noisyG = ofNoise(t * 0.73); // guarantee that our color channels are float noisyB = ofNoise(t * 0.81); // not all (apparently) synchronized. ofEnableSmoothing(); ofEnableAlphaBlending(); ofSetCircleResolution(12); ofSetLineWidth(1.0); ofPushMatrix(); // Translate over to the shoulder location; draw it ofTranslate(ofGetWidth()/2, 540, 0); ofRotate(shoulderNoiseAngleDegrees, 0, 0, 1); drawNoisyArmRect(100,24); // Translate over to the forearm location; draw it ofTranslate(76, 0, 0); ofRotate(elbowNoiseAngleDegrees, 0, 0, 1); drawNoisyArmRect(90,16); // Translate over to the hand location; draw it. // Note that the color of the 'hand' is controlled by noise. ofTranslate(74, 0, 0); ofRotate(wristNoiseAngleDegrees, 0, 0, 1); ofSetCircleResolution(5); // a kludgy "pentagon" ofFill(); ofSetColor (ofFloatColor(noisyR, noisyG, noisyB, 0.75)); ofEllipse(-10,0, 60,60); ofNoFill(); ofSetColor(0); ofEllipse(-10,0, 60,60); ofSetCircleResolution(12); ofSetColor(0); ofFill(); ofEllipse(0,0, 7,7); ofPopMatrix(); }
void wSatellite::place( float _alt, ofVec3f _orbit ){ altitud.set(0,0,_alt); orbit = _orbit;//.normalize(); freq = ofNoise(lat*0.01,lon*0.01); // meshIndex = satelliteMesh->getNumVertices(); // satelliteMesh->addVertex(*this); }