Beispiel #1
0
void FlowField::init() {
    if (!bSetup) {
        ofLog(OF_LOG_WARNING, "call setup() first");
        return;
    }

    // Reseed noise so we get a new flow field every time
    ofSeedRandom();//TODO not working for noise()!
    float seed = ofRandom(10000);
    float xoff = 0;
    for (int i = 0; i < cols; ++i) {
        float yoff = 0;
        for (int j = 0; j < rows; ++j) {
            float zoff = 0;
            for(int k = 0; k < depth; ++k) {
                // Use perlin noise to get an angle between 0 and 2 PI
                float theta = ofMap(ofSignedNoise(seed,xoff, yoff,0), 0, 1, 0, TWO_PI);//TODO ofSignedNoise
                float alpha = ofMap(ofSignedNoise(seed,xoff, 0, zoff), 0 ,1 ,0, TWO_PI);
                // Polar to cartesian coordinate transformation to get x and y components of the vector
                field[i][j][k].set(cos(theta), sin(theta), sin(alpha));
                zoff += 0.1;
            }
            yoff += 0.1;
        }
        xoff += 0.1;
    }
}
Beispiel #2
0
	void updateMesh(ofMesh& mesh)
	{
		float t = ofGetElapsedTimef();
		
		ofVec3f axis;
		axis.x = ofSignedNoise(1, 0, 0, t);
		axis.y = ofSignedNoise(0, 1, 0, t);
		axis.z = ofSignedNoise(0, 0, 1, t);
		axis.normalize();
		
		vector<ofVec3f>& verts = mesh.getVertices();
		vector<ofVec3f>& norms = mesh.getNormals();
		for (int i = 0; i < verts.size(); i++)
		{
			ofVec3f& v = verts[i];
			ofVec3f& n = norms[i];
			ofVec3f vv = v;
			
			float r = vv.y * fmodf(t, 10) * 0.1;
			
			vv.rotate(r, axis);
			n.rotate(r, axis);
			
			v = vv;
		}
	}
Beispiel #3
0
//-----------------------------------------------------------------------------------------
//
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
    }
    
    
}
Beispiel #4
0
void ParticleState::update() {
    
    // パーティクルの座標を更新
    float t   = (ofGetElapsedTimef()) * 0.9f;
    float div = 250.0;
    
    for (int i=0; i<NUM_BILLBOARDS; i++) {
        
        // ノイズを生成し移動速度に
        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 *= 0.3f;
        
        // 速度をもとにパーティクル位置を更新
        billboardVels[i] += vec;
        billboardVerts[i] += billboardVels[i];
        billboardVels[i]  *= 0.94f;
    }
    
    // VBOの頂点と色の情報を更新
    billboardVbo.setVertexData(billboardVerts, NUM_BILLBOARDS, GL_DYNAMIC_DRAW);
    billboardVbo.setColorData(billboardColor, NUM_BILLBOARDS, GL_DYNAMIC_DRAW);
    
    // カメラのズーム設定
    zoom += (zoomTarget - zoom) * 0.01;
    cam.setDistance(zoom);
}
void PlateauScene::update(){
    //matFloor.updateParameters();
    matPlateau.updateParameters();
    
    ofVec3f floorAlignedPlateauPosition(plateauPosition);
    floorAlignedPlateauPosition.y += -plateauSize->y / 2.0;

//    plateauPivotOrigin.set(ofVec3f(ofSignedNoise(ofGetElapsedTimef())*100.0, plateauPivotOrigin->y, ofSignedNoise(ofGetElapsedTimef()+0.33235)*100.0));
    
    ofVec3f plateauPivotOriginTranslated = plateauPivotOrigin.get() + plateauPosition.get();

    noiseTime += ofGetLastFrameTime() * plateauPivotNoiseSpeed;
    
    pivotNoise.set(ofSignedNoise(noiseTime+0.33253)*plateauPivotNoiseAmount, 0, ofSignedNoise(noiseTime+44.0523)*plateauPivotNoiseAmount);
    
    ofQuaternion q;
    q.makeRotate(
                 ofVec3f(plateauPosition.get() + ofVec3f(plateauPivotOrigin->x, 0, plateauPivotOrigin->z) + pivotNoise) - plateauPivotOriginTranslated,
                 dp(1) - plateauPivotOriginTranslated
                 );
    pivotMatrix.makeIdentityMatrix();
    pivotMatrix.translate(floorAlignedPlateauPosition);
    pivotMatrix.translate(-dp(1));
    pivotMatrix.rotate(q);
    pivotMatrix.translate(dp(1));
    plateau.setTransformMatrix(pivotMatrix);
//    plateau.pan(plateauRotation->y);
}
Beispiel #6
0
//--------------------------------------------------------------
void testApp::draw() {
    
    if(!bHideGUI) {
       
        // slider
        pointSlider.draw();
        minDisSlider.draw();  
        
        // instructions
        ofSetColor(90);
        ofDrawBitmapString("press space to make points\npress v to make vonios", 20, 100);
    }
    
    
    
    // the bounds of all the points
    ofSetColor(90);
    ofNoFill();
    ofRect(voronoi.getBounds());
    
    
    
    
    if(voronoi.getPoints().size() > 0) {
    
        // draw the points
        vector <ofPoint> &pts = voronoi.getPoints();
        
        for (int i=0; i<pts.size(); i++) {
            
            if(bMove) {
                
                float div = 6000.0;
                pts[i].x += ofSignedNoise(ofGetElapsedTimef()*0.1, pts[i].y/div) * 10;
                pts[i].y += ofSignedNoise(pts[i].x/div, ofGetElapsedTimef()*0.1) * 10;
                
                if(pts[i].x > ofGetWidth())  pts[i].x = 0;
                if(pts[i].x < 0)             pts[i].x = ofGetWidth();
                if(pts[i].y > ofGetHeight()) pts[i].y = 0;
                if(pts[i].y < 0)             pts[i].y = ofGetHeight();
            }
            
            ofCircle(pts[i], 1);
            
        }
        
        // set the min
        voronoi.setMinDistance(minDisSlider.getValue());
        
        bool bMade = voronoi.generateVoronoi();
        for(int i=0; i<voronoi.edges.size(); i++) {
            
            ofVec2f a = voronoi.edges[i].a;
            ofVec2f b = voronoi.edges[i].b;
            
            ofLine(a, b);
        }
    }
    
}
Beispiel #7
0
void Particle::applyFlockingForce(bool bAccountForTargetForce){
	
	float basex = (position.x / neighborhood)*Particle::noiseScaleInput;
	float basey = (position.y / neighborhood)*Particle::noiseScaleInput;
	float basez = (position.z / neighborhood)*Particle::noiseScaleInput;
	
	ofVec3f addToForce;
	
    addToForce.x +=
	ofSignedNoise(
				  basex + (globalOffset.x + localOffset.x * independence),
				  basey,
				  basez)*Particle::noiseScaleOutput;
	addToForce.y +=
	ofSignedNoise(
				  basex,
				  basey + (globalOffset.y  + localOffset.y * independence),
				  basez)*Particle::noiseScaleOutput;
	addToForce.z +=
	ofSignedNoise(
				  basex,
				  basey,
				  basez + (globalOffset.z + localOffset.z * independence))*Particle::noiseScaleOutput;


	if( bAccountForTargetForce ){
		addToForce *= (1-targetForce);
	}
	
	force += addToForce;
	
}
void CloudsRGBDCamera::setPositionFromMouse() {

    float percentOnCurve = ofMap(GetCloudsInputX(), canvasWidth*.2, canvasWidth*.8, 0, 1, true);
    ofVec3f sidePositionLeft  = lookTarget + ofVec3f(-sideDistance,0,sidePullback);
    ofVec3f sidePositionRight = lookTarget + ofVec3f( sideDistance,0,sidePullback);
    ofVec3f frontPosition = lookTarget + ofVec3f(0,0,-frontDistance);
    ofVec3f position;
    if(percentOnCurve > .5) {
        position = frontPosition.getInterpolated(sidePositionRight, ofMap(percentOnCurve, .5, 1.0, 0, 1.0) );
    }
    else {
        position = sidePositionLeft.getInterpolated(frontPosition, ofMap(percentOnCurve, 0, .5, 0, 1.0) );
    }

    float liftDrift = ofMap(GetCloudsInputY(), canvasHeight*.2, canvasHeight*.8, -liftRange,liftRange, true);
    position.y += ofMap(abs(.5 - percentOnCurve), 0, .5, (liftDrift + liftAmount), (liftDrift-liftAmount)*.5);
    position.z -= MAX(liftDrift,0) * .5; // zoom in on mouse up

    targetPosition = position;
    currentPosition += (targetPosition - currentPosition) * damp;

    currentLookTarget = lookTarget - ofVec3f(0,dropAmount,-sidePullback);

    //calculate drift;
    //ofVec3f driftOffset(0,0,0);
    ofVec3f driftPosition = currentPosition;
    float channelA = 1000;
    float channelB = 1500;
    if(maxDriftAngle > 0) {
        ofVec3f toCamera = currentPosition - currentLookTarget;
        ofQuaternion driftQuatX,driftQuatY;

        driftNoisePosition += driftNoiseSpeed;// * (ofGetElapsedTimef() - ofGetLastFrameTime());
        float driftX = ofSignedNoise( channelA, driftNoisePosition );
        float driftY = ofSignedNoise( channelB, driftNoisePosition );

        driftPosition.rotate(driftX*maxDriftAngle, currentLookTarget, ofVec3f(0,1,0));
        driftPosition.rotate(driftY*maxDriftAngle, currentLookTarget, ofVec3f(1,0,0));

//		driftQuatX.makeRotate(maxDriftAngle*driftX, 0, 1, 0);
//		driftQuatY.makeRotate(maxDriftAngle*driftY, 1, 0, 0);
//		driftOffset = driftQuatX * driftQuatY * (ofVec3f(0,0,1) * toCamera.length());
    }

    mouseBasedNode.setPosition(driftPosition);
    mouseBasedNode.lookAt(currentLookTarget);

    //Compute new FOV
    bool onEdge = GetCloudsInputX() < 20 || GetCloudsInputX() > canvasWidth - 40 ||
                  GetCloudsInputY() < 20 || GetCloudsInputY() > canvasHeight - 40;
    float newFov;
    if(onEdge) {
        newFov = getFov() + ( zoomFOVRange.max - getFov() ) * .05;
    }
    else {
        newFov = getFov() + (zoomFOVRange.min - getFov() ) * .005;
    }
    setFov(newFov);

}
void Critter::update(ofVec2f nearestHand) {

    ofVec2f nh = nearestHand;
	nextFrame += ofMap(v, 0, 10, 0, 2);
	currentFrame = floor(nextFrame);
	if(currentFrame >= numFrames) {
		currentFrame = 0;
		nextFrame = 0;
	}
	bool draw = true;
	for (int i = 0; i < previousFrames.size(); ++i)
	{ 
		if(previousFrames[i])
			draw = false;
	}
	if(!hidden && draw) {
		p.x += v * cos(d/180*PI);
		p.y += v * sin(d/180*PI); 
	}
    
	float time = ofGetElapsedTimef();
	v += 	ofSignedNoise(time * TIME_SCALE + offsets[0]) * VELOCITY_DISPLACEMENT_SCALE;
	d += 	ofSignedNoise(time * TIME_SCALE + offsets[1]) * DIRECTION_DISPLACEMENT_SCALE;

	v = ofMap(v, MIN_VELOCITY, MAX_VELOCITY, MIN_VELOCITY, MAX_VELOCITY, true);
	d = ofWrapDegrees(d);

	if(nh.length() != 0) {
		ofVec2f vel = ofVec2f(v * cos(d/180*PI), v * sin(d/180*PI));
		float fear = ofMap(nh.length(), 500, 0, 0, 1, true);
        float angle = vel.angle(nh);
		d += ofMap((abs(angle) - 180) * fear, -180, 0, -30 * (angle)/abs(angle), 0);
		v += ofMap((abs(angle) - 90) * fear, -90, 90, -0.3, 0.5);
	}
}
void Particle::update(ofVec2f _force){
    
    if(bNoise){
        counterX += counterInc;
        counterY += counterInc;
        vel.x += 2*ofSignedNoise(counterX);
        vel.y += 2*ofSignedNoise(counterY);
    } else {
    
        vel += acc;
    }
    
    loc += vel;
    
    lifeSpan -= ageSpeed;
    if(lifeSpan <= 0){
        bTimeToDie = true;
    }
    

    
    if(loc.x >= maxW
       || loc.x <= 0
       || loc.y >= maxH
       || loc.y <= 0){
        bTimeToDie = true;
    }
}
Beispiel #11
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    ofBackgroundGradient(ofColor::gray, ofColor::black, OF_GRADIENT_LINEAR);
    
    
    cam.begin();
    glEnable(GL_DEPTH_TEST);
    ofSetColor(255);
    ofRotateY(90);
    mesh.draw();
    
    
    
    //modify mesh with some noise
    float liquidness = 10;
    float amplitude = mouseY/100.0;
    float speedDampen = 5;
    vector<ofVec3f>& verts = mesh.getVertices();
    for(unsigned int i = 0; i < verts.size(); i++){
        verts[i].x += ofSignedNoise(verts[i].x/liquidness, verts[i].y/liquidness,verts[i].z/liquidness, ofGetElapsedTimef()/speedDampen)*amplitude;
        verts[i].y += ofSignedNoise(verts[i].z/liquidness, verts[i].x/liquidness,verts[i].y/liquidness, ofGetElapsedTimef()/speedDampen)*amplitude;
        verts[i].z += ofSignedNoise(verts[i].y/liquidness, verts[i].z/liquidness,verts[i].x/liquidness, ofGetElapsedTimef()/speedDampen)*amplitude;
    }
    

    
    ofPopMatrix();
    cam.end();
}
//------------------------------------------------------------------------------------
void vectorField::addNoise( float _scale  ,float _speed, float _turbulence, bool _signed){
    
    float t = ofGetElapsedTimef() * 0.5;
    
    for (int i = 0; i < fieldWidth; i++){
        for (int j = 0; j < fieldHeight; j++){
            // pos in array
            int pos = j * fieldWidth + i;
            
            float normx = ofNormalize(i, 0, fieldWidth);
            float normy = ofNormalize(j, 0, fieldHeight);
            
            float u, v;
            if (_signed){
                u = ofSignedNoise(t + TWO_PI, normx * _turbulence + TWO_PI, normy * _turbulence + TWO_PI);
                v = ofSignedNoise(t - TWO_PI, normx * _turbulence - TWO_PI, normy * _turbulence + TWO_PI);
            } else {
                u = ofNoise(t + TWO_PI, normx * _turbulence + TWO_PI, normy * _turbulence + TWO_PI);
                v = ofNoise(t - TWO_PI, normx * _turbulence - TWO_PI, normy * _turbulence + TWO_PI);
            }
            
            ofPoint force = ofPoint(u,v,0.0) ;
            field[ pos ] = field[ pos ] * (1.0-_scale) + force * _scale;
        }
    }
}
//--------------------------------------------------------------
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, billboards.getVertex(i).y/div, billboards.getVertex(i).z/div),
								ofSignedNoise(billboards.getVertex(i).x/div, t, billboards.getVertex(i).z/div),
								ofSignedNoise(billboards.getVertex(i).x/div, billboards.getVertex(i).y/div, t));
		
		vec *= 10 * ofGetLastFrameTime();
		billboardVels[i] += vec;
		billboards.getVertices()[i] += billboardVels[i]; 
		billboardVels[i] *= 0.94f; 
    	billboards.setNormal(i,ofVec3f(12 + billboardSizeTarget[i] * ofNoise(t+i),0,0));
	}
	
	
	// 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;
	
}
Beispiel #14
0
void Ribbon::draw()
{
    ofPushStyle();
    ofNoFill();
    ofSetLineWidth(lineWidth);
    ofSetColor(contour->color, ofMap(abs(age - maxAge * 0.5), 0, maxAge * 0.5, maxAlpha, 0));
    ofBeginShape();
    for (int i = 0; i < points.size(); i++)
    {
        if (match)
        {
            idxMatched  = floor(contour->points.size() * lookupMatched[i]);
            points[i].x = ofLerp(points[i].x, contour->points[idxMatched].x +
                                 margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 5), lerpRate);
            points[i].y = ofLerp(points[i].y, contour->points[idxMatched].y +
                                 margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 10), lerpRate);
        }
        else
        {
            points[i].x = ofLerp(points[i].x, contour->points[lookup[i]].x +
                                 margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 5), lerpRate);
            points[i].y = ofLerp(points[i].y, contour->points[lookup[i]].y +
                                 margin * ofSignedNoise(i * noiseFactor, ageFactor * age, 10), lerpRate);
        }
        
        curved ? ofCurveVertex(points[i].x, points[i].y) : ofVertex(points[i].x, points[i].y);
    }
    ofEndShape();
    ofPopStyle();
}
//------------------------------------------------------------------------------------
void vectorField::setFromPerlin(float scale, float time, float amount){
	int externalWidth = topPoint.x - bottomPoint.x;
	int externalHeight = topPoint.y - bottomPoint.y;
	int externalDepth = topPoint.z - bottomPoint.z;
	
	
	float scalef = scale;
	float timef = time;
    float scalex = (float)externalWidth / (float)fieldWidth;
    float scaley = (float)externalHeight / (float)fieldHeight;
	float scalez = (float)externalDepth / (float)fieldDepth;
	
    for (int i = 0; i < fieldWidth; i++){
        for (int j = 0; j < fieldHeight; j++){
			for (int k = 0; k < fieldDepth; k++){
				
				// pos in array
				int pos = (k * (fieldWidth * fieldHeight) + j * fieldWidth + i);
				// pos externally
				float px = 	bottomPoint.x + i * scalex;
				float py =  bottomPoint.y + j * scaley;
				float pz = 	bottomPoint.z + k * scalez;
				
				
				float nx = ofSignedNoise(px/scalef, py/scalef, pz/scalef, 0 + timef);
				float ny = ofSignedNoise(px/scalef, py/scalef, pz/scalef, 666767 + timef);
				float nz = ofSignedNoise(pz/scalef, py/scalef, pz/scalef, 10000000*10 + timef);
				
				field[pos].set(nx*amount, ny*amount, nz*amount);
			}
		}
	}
}
Beispiel #16
0
void ofxPerlinBehavior::actUpon(ofxRParticle particle, ofVec3f &pos, ofVec3f &vel, ofVec3f &acc, float dt)
{
    float nx = ofSignedNoise(pos.x * 0.025, ofGetElapsedTimef(), particle.getID()*0.001);
    float ny = ofSignedNoise(pos.y * 0.025, ofGetElapsedTimef(), particle.getID()*0.001);
    float nz = ofSignedNoise(pos.z * 0.025, ofGetElapsedTimef(), particle.getID()*0.001);
    
    acc+=ofVec3f(nx, ny, nz)*(*magnitude)*dt;
}
Beispiel #17
0
// -------------------------------
void Boid::addNoise() 
{
    ofPoint noise;
    noise.x = ofSignedNoise(ofGetFrameNum() / 100.0, _noiserow.x);
    noise.y = ofSignedNoise(ofGetFrameNum() / 100.0, _noiserow.y);
    
    acc += (noise/40.0);
}
Beispiel #18
0
void Field::update()
{
    if (!isAllEnabled) return;
    float t = (ofGetElapsedTimef() + randomity) * movementSpeed;

    fieldPos.x = ofSignedNoise(t, 0) * playArea;
    fieldPos.y = ofSignedNoise(0, t) * playArea;
}
Beispiel #19
0
//--------------------------------------------------------------
void testApp::drawPointCloud() {
	int w = 640;
	int h = 480;
	ofMesh mesh;
	mesh.setMode(OF_PRIMITIVE_POINTS);
    
	for(int y = 0; y < h; y += step) {
		for(int x = 0; x < w; x += step) {
			if(kinect.getDistanceAt(x, y) > 0) {
                ofColor meshCol;
				switch (colorMode) {
                    case 0:
                        meshCol = kinect.getColorAt(x,y);
                        break;
                        
                    case 1:
                        meshCol.set((int)ofMap(kinect.getDistanceAt(x,y), 0, 10000, 255, 0));
                        break;
                        
                    case 2:
                        meshCol.set(255,255,0);
                        meshCol.setHue((int)ofMap(kinect.getDistanceAt(x,y), 0, 10000, 0, 255));
                        break;
                        
                    case 3:
                        meshCol = kinect.getColorAt(x,y);
                        meshCol.setHue((int)ofMap(kinect.getDistanceAt(x,y), 0, 10000, 0, 255));
                        break;
                }

                ofVec3f v = kinect.getWorldCoordinateAt(x, y);
                switch (vMode) {
                    case 0:
                        break;
                        
                    case 1:
                        v.z += ofSignedNoise(ofGetElapsedTimef(), x * 0.002, y * 0.002) * 500;
                        break;
                        
                    case 2:
                        v.z += ofSignedNoise(ofGetElapsedTimef() * 0.7, v.z * 0.002) * 500;
                        break;
                }
                
                mesh.addColor(meshCol);
				mesh.addVertex(v);
			}
		}
	}
    
	glPointSize(5);
	ofPushMatrix();
    ofScale(zoom,zoom,1);
	ofScale(1, -1, -1); // the projected points are 'upside down' and 'backwards'
	mesh.drawVertices();
	ofPopMatrix();
}
Beispiel #20
0
//--------------------------------------------------------------
void ofApp::audioIn(float * input, int bufferSize, int nChannels){	
	
	for (int i = 0; i < bufferSize; i++) {
		left[i] = input[i * 2] / 30;
		right[i] = input[i * 2 + 1] / 30;
	}

	bufferCounter++;


	if (index < 80)
		index += 1;
	else
		index = 0;

	myfft.powerSpectrum(0, (int)BUFFER_SIZE / 2, &left[0], BUFFER_SIZE, &magnitude[0], &phase[0], &power[0], &avg_power);


	/* start from 1 because mag[0] = DC component */
	/* and discard the upper half of the buffer */
	for (int j = 1; j < BUFFER_SIZE / 2; j++) {
		freq[index][j] = magnitude[j];
	}



	for (int i = 0; i<N; i++) {
		spectrum[i] *= 0.97;	//Slow decreasing
		spectrum[i] = max(spectrum[i], magnitude[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);
	Vel = ofMap(spectrum[bandVel], 0, 0.1, 0.05, 0.5);

	//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;
	}
	
}
Beispiel #21
0
//--------------------------------------------------------------
void Particle::addNoiseForce(float scale) {
    ofVec2f noiseFrc;
    float fakeWindX = ofSignedNoise(pos.x * 0.003, pos.y * 0.006, ofGetElapsedTimef() * 0.6);
    
    noiseFrc.x = ofSignedNoise(uniquef, pos.y * 0.006) * 0.06;
    noiseFrc.y = ofSignedNoise(uniquef, pos.x * 0.006, ofGetElapsedTimef()*0.2) * 0.06;
    noiseFrc *= scale;
    frc += noiseFrc;
}
//--------------------------------------------------------------
void testApp::draw(){
    for(int i=0; i<P.size(); i++){
        ofSetColor(ofRandom(255),ofRandom(255),ofRandom(255));
    //    ofSetColor(sin(ofMap(ofGetElapsedTimef(),-1,1,0,1))*255);
        
    ofCircle(P[i]+ofPoint(ofSignedNoise(ofRandom(100))*100,ofSignedNoise(ofRandom(100))*100), 2);
        
    }

}
Beispiel #23
0
//--------------------------------------------------------------
void testApp::update()
{
	sys.get()->setCameraPosition(ofxSPK::toSPK(cam.getPosition()));
	sys.update();

	em.setPosition(ofSignedNoise(1, 0, 0, ofGetElapsedTimef() * 0.5) * 1400,
				   ofSignedNoise(0, 1, 0, ofGetElapsedTimef() * 0.5) * 1400,
				   ofSignedNoise(0, 0, 1, ofGetElapsedTimef() * 0.5) * 1400);

	em.tilt(0.1);
	em.pan(15);
	em.roll(-3.5);

	em.update();

	mod.update();
	mod2.update();

	mod.setPosition(ofSignedNoise(100, 0, 0, ofGetElapsedTimef() * 0.1) * 1000,
				   ofSignedNoise(0, 100, 0, ofGetElapsedTimef() * 0.1) * 1000,
				   ofSignedNoise(0, 0, 100, ofGetElapsedTimef() * 0.1) * 1000);

	mod2.setPosition(ofSignedNoise(500, 0, 0, ofGetElapsedTimef() * 0.5) * 200,
					ofSignedNoise(0, 500, 0, ofGetElapsedTimef() * 0.5) * 200,
					ofSignedNoise(0, 0, 500, ofGetElapsedTimef() * 0.5) * 200);

	ofSetWindowTitle(ofToString(ofGetFrameRate()));
}
Beispiel #24
0
//--------------------------------------------------------------
void ofApp::update(){
//-------------------------
    
    bool bNewFrame = false;
    vidGrabber.update();
    bNewFrame = vidGrabber.isFrameNew();
    if (bNewFrame){  // if we have a new frame
        colorImg.setFromPixels(vidGrabber.getPixels());
        grayImage = colorImg;
        if (bLearnBakground == true){  // if we hit space, this grabs a "control" image
            grayBg = grayImage;		// copys the pixels from grayImage into grayBg
            bLearnBakground = false;
        }
        grayDiff.absDiff(grayBg, grayImage);
        grayDiff.threshold(threshold);
        // find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
        // find max 10 blobs with no holes in them
        contourFinder.findContours(grayDiff, 20, (vidX*vidY)/3, 10, false);	// false == dont find holes in our blobs
    }
    
    if (bSendSerialMessage){
        serial.writeByte('a');
        nTimesRead = 0;
        nBytesRead = 0;
        int nRead;
        
        unsigned char bytesReturned[3];
        
        memset(bytesReadString, 0, 4);
        memset(bytesReturned, 0, 3);
        
        while( (nRead = serial.readBytes( bytesReturned, 3)) > 0){
            nTimesRead++;
            nBytesRead = nRead;
        };
        
        memcpy(bytesReadString, bytesReturned, 3);
        
        bSendSerialMessage = false;
        readTime = ofGetElapsedTimef();
    }
    
    mov1.update();
    
    for(unsigned int i = 0; i < p.size(); i++){
        p[i].setMode(currentMode);
        p[i].update();
    }
    for(unsigned int i = 0; i < attractPointsWithMovement.size(); i++){
        attractPointsWithMovement[i].x = attractPoints[i].x + ofSignedNoise(i * 10, ofGetElapsedTimef() * 0.7) * 12.0;
        attractPointsWithMovement[i].y = attractPoints[i].y + ofSignedNoise(i * -10, ofGetElapsedTimef() * 0.7) * 12.0;
    }
    
}
Beispiel #25
0
void Particle::applyFlockingForce(ofPoint * _offset, float _neighbordhood, float _independece, float _scale){
    addForce( ofVec3f(ofSignedNoise(pos.x / _neighbordhood + _offset->x + localOffset.x * _independece,
                                    pos.y / _neighbordhood,
                                    pos.z / _neighbordhood),
                      ofSignedNoise(pos.x / _neighbordhood,
                                    pos.y / _neighbordhood + _offset->y  + localOffset.y * _independece,
                                    pos.z / _neighbordhood),
                      ofSignedNoise(
                                    pos.x / _neighbordhood,
                                    pos.y / _neighbordhood,
                                    pos.z / _neighbordhood + _offset->z + localOffset.z * _independece)) * _scale );
}
Beispiel #26
0
//--------------------------------------------------------------
void ofApp::update(){
	for(unsigned int i = 0; i < p.size(); i++){
		p[i].setMode(currentMode);
		p[i].update();
	}
	
	//lets add a bit of movement to the attract points
	for(unsigned int i = 0; i < attractPointsWithMovement.size(); i++){
		attractPointsWithMovement[i].x = attractPoints[i].x + ofSignedNoise(i * 10, ofGetElapsedTimef() * 0.7) * 12.0;
		attractPointsWithMovement[i].y = attractPoints[i].y + ofSignedNoise(i * -10, ofGetElapsedTimef() * 0.7) * 12.0;
	}	
}
Beispiel #27
0
//-----------------------------------------------------------------------------------------
//
void ofApp::update()
{
    float time = ofGetElapsedTimef();

    for (int y=0; y<H; y++) {
        for (int x=0; x<W; x++) {
            int i = x + W * y;			//Vertex index
            ofPoint p = mesh.getVertex( i );

            //the following equation is based on the linear theory of ocean surface waves
            // assuming the amplitude of waves on the water surface is infinitely small so the surface is almost exactly a plane. To simplify the mathematics, we can also assume that the flow is 2-dimensional with waves traveling in the x-direction.
            //read more details on http://oceanworld.tamu.edu/resources/ocng_textbook/chapter16/chapter16_01.htm
            
            freq = sqrt(g * k);
            float height = amp * sin(k * x - freq * time * 2);

            // the z position of each mesh vertex are determined by the x position, the height that's caculated by the linear theory of the ocean suface wave, and ofSignedNoise, which returns a number between -1 and 1
            p.z  = (W-x)/7.f * ofSignedNoise(height * .001, y*.007, height)+ofSignedNoise(x * .01, y*.08, height);
            
          //  p.z  = (W-x)/15.f * height * ofSignedNoise(height * .001, y*.007 );
                
            mesh.setVertex( i, p );
            
            //The color of vertex changes as the z position goes up and down
            mesh.setColor(i, ofFloatColor( (abs(height) + .5) * 30/255.f,
                                          (abs(height) + .5) * 80/255.f,
                                          (abs(height) + .5)*100/255.f));
            
//            mesh.setColor( i, ofFloatColor(
//                                ofMap(height, amp, -amp, 60, 100)/255.f,
//                               1- ofMap(height, amp, -amp, 200, 250)/255.f,
//                                ofMap(height, amp, -amp, 200, 250)/255.f
//                                           ));
       
            
        }
    }
    setNormals( mesh );
    
    //the light moves position and changes color
    pointLight.setPosition((ofGetWidth()*.5)+ cos(ofGetElapsedTimef()*.5)*(ofGetWidth()*.3), ofGetHeight()/2, 500);
    pointLight2.setPosition((ofGetWidth()*.5)+ cos(ofGetElapsedTimef()*.15)*(ofGetWidth()*.3),
                            ofGetHeight()*.5 + sin(ofGetElapsedTimef()*.7)*(ofGetHeight()), -300);
    
    pointLight3.setPosition(
                            cos(ofGetElapsedTimef()*1.5) * ofGetWidth()*.5,
                            sin(ofGetElapsedTimef()*1.5f) * ofGetWidth()*.5,
                            cos(ofGetElapsedTimef()*.2) * ofGetWidth()
                            );
 
}
Beispiel #28
0
//--------------------------------------------------------------
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();
}
Beispiel #29
0
//--------------------------------------------------------------
void ofApp::update(){
	//Update sound engine
	ofSoundUpdate();

	//Get current spectrum with N bands
	float *val = ofSoundGetSpectrum( 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 );
	Vel = ofMap( spectrum[ bandVel ], 0, 0.1, 0.05, 0.5 );

	//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;
	}

    if (bg_transparent > 0){
        bg_transparent = 255 - time * 3.5;
    }
    else{
        bg_transparent = 0;
    }

}
//--------------------------------------------------------------
void ofApp::update(){
    for (int i = 0; i < max; i++){
        float step = 2*PI/max; // step size around circle
        float theta = ofMap(i, 0, max-1, 0, 2*PI - step); //map i as circle divisions to actual radian values around the circle (note we don't go quite all the way around by one step, because it will be the same as where we started, so we'll just index that starting vertex when we make faces)
        float t = ofGetElapsedTimef();
        ofVec3f tmpVec = mesh.getVertex(i);
        tmpVec.x = radius*cos(theta) * ofSignedNoise(theta * t * mXmulti);
        tmpVec.y = radius*sin(theta) * ofSignedNoise(theta * t * mYmulti);
        tmpVec.z = radius*zamt*sin(zfreq*theta) * ofSignedNoise(theta * t * mZmulti);
        
        
        mesh.setVertex(i, tmpVec);
    }
}