Exemplo n.º 1
0
Arquivo: cApp.cpp Projeto: stdmtb/n9
void cApp::draw(){

    float transx = getWindowWidth()/2 - mFpb/2/2;
    float transy = getWindowHeight()/2;
    
    mExp.beginPersp();
    {
        gl::clear( Colorf(0,0,0) );
        
        glPushMatrix();
        {
            glTranslatef( transx, transy, 0 );
            
            for( int w=0; w<mWaves.size(); w++ ){

                for( int i=0; i<mWaves[w].posL.size(); i++ ){
                    
                    float noise = mPln.noise( mWaves[w].posR[i].y*mWaves[w].posL[i].y*0.5, i*0.5 );
                    if( noise<0.67 ){
                        glPointSize( 1 );
                    }else if( noise<0.72 ){
                        glPointSize( 2 );
                    }else if( noise<0.8 ){
                        glPointSize( 3 );
                    }else{
                        glPointSize( 1 );
                        gl::drawStrokedCircle( Vec2f(mWaves[w].posL[i].x, mWaves[w].posL[i].y), MAX(1, (noise-0.8f)*200.0f) );
                    }
                    
                    if(randFloat()<0.97f) glColor3f( mWaves[w].colorL[ i ].r, mWaves[w].colorL[ i ].g, mWaves[w].colorL[ i ].b );
                    else glColor3f(1, 0, 0);

                    glBegin( GL_POINTS );
                    glVertex2f( mWaves[w].posL[i].x,  mWaves[w].posL[i].y );
                    glEnd();
                    
                    if(randFloat()<0.97f) glColor3f( mWaves[w].colorR[i].r, mWaves[w].colorR[i].g, mWaves[w].colorR[i].b );
                    else glColor3f(1, 0, 0);

                    glBegin( GL_POINTS );
                    glVertex2f( mWaves[w].posR[i].x, mWaves[w].posR[i].y );
                    glEnd();
                }
            }
        }
        glPopMatrix();
        
    }
    mExp.end();
    

    gl::clear( Colorf(1,1,1) );
    gl::color( Colorf(1,1,1) );
    mExp.draw();
}
Exemplo n.º 2
0
void HelloWorld::setWind(float dt)
{
    Perlin perlin;
    float pwind = perlin.noise(-0.5f, 0.5f, 0);
    CCLOG("Wind is %f",pwind);

    auto my_prog = ShaderCache::getInstance()->getGLProgram("perlin_wind");
    auto my_state = GLProgramState::getOrCreateWithGLProgram(my_prog);

    my_state->setUniformFloat("u_wind", pwind);

}
Exemplo n.º 3
0
Arquivo: cApp.cpp Projeto: stdmtb/n9
void cApp::update(){

    const int frame = getElapsedFrames()-1;
    const int audioPos = frame * 192000.0f/25.0f;
    
    gap = frame * 0.002f + (mPln.noise(randFloat(), randFloat()) * 0.01);
    
    for( int w=0; w<mWaves.size(); w++ ){
        
        //mWaves[w].player->seek(audioPos);
        
        // Update Wave pos
        Vec2f scale(0.5f, 200);

        const float * ch0 = mWaves[w].buf->getChannel( 0 );
        const float * ch1 = mWaves[w].buf->getChannel( 1 );
        
        for ( int i=0; i<mFpb; i++) {
            float l = ch0[audioPos + i];
            float r = ch1[audioPos + i];

            l += l>0 ? gap : -gap;
            r += r>0 ? gap : -gap;
            
            Vec3f newL = Vec3f(i*scale.x, l*scale.y, 0);
            Vec3f newR = Vec3f(i*scale.x, r*scale.y, 0);

            mWaves[w].posL[i] = newL;
            mWaves[w].posR[i] = newR;
        }
        
        // Update Wave Color
        int sk = 8;
        int blockw = 64;
        int fx = randInt(0, mColorSample1.size() - blockw*sk);
        int fy = randInt(0, mColorSample1[0].size() -blockw*sk);
        
        for( int j=0; j<blockw; j++ ){
            for( int k=0; k<blockw; k++ ){
                mWaves[w].colorL[j*blockw+k].r =  mColorSample1[fx+j*sk][fy+k*sk].b;
                mWaves[w].colorL[j*blockw+k].g =  mColorSample1[fx+j*sk][fy+k*sk].g;
                mWaves[w].colorL[j*blockw+k].b =  mColorSample1[fx+j*sk][fy+k*sk].r;
                
                mWaves[w].colorR[j*blockw+k].r =  mColorSample2[fx+j*sk][fy+k*sk].b;
                mWaves[w].colorR[j*blockw+k].g =  mColorSample2[fx+j*sk][fy+k*sk].r;
                mWaves[w].colorR[j*blockw+k].b =  mColorSample2[fx+j*sk][fy+k*sk].g;
                
                mWaves[w].colorL[j*blockw+k].a = 0.8;
                mWaves[w].colorR[j*blockw+k].a = 0.8;
            }
        }
    }
}
Exemplo n.º 4
0
float noise_fractal_brownian_motion(Perlin noise, int octaves, float x, float y, float z) {
	const float lacunarity = 1.9f;
	const float gain = 0.35f;
	float sum = 0.0f;
	float amplitude = 1.0f;
	int i;
	for (i = 0; i < octaves; i++) {
		sum += amplitude * noise.noise(x, y, z);
		amplitude *= gain;
		x *= lacunarity;
		y *= lacunarity;
		z *= lacunarity;
	}
	return sum;
}
Exemplo n.º 5
0
void CinderGridApp::draw()
{
	gl::clear( Color( 0, 0, 0 ));
    
    Perlin perlin;
    for(int y = 0; y < 100; y++) {
        for(int x = 0; x < 100; x++) {
            float noiseVal = perlin.noise(x * 0.05, y * 0.15, frameCount / 50.0f);
            float r = ((0.3 + noiseVal) * (0.3 + noiseVal)) * 8.;
            float gridSpace = 10;
            gl::color(noiseVal + 0.3, 1.0 - (noiseVal * 0.5), (noiseVal + 0.8) / 2.);
            gl::drawSolidCircle( Vec2f((gridSpace * x), (gridSpace * y)) , r);
        }
    }
    
    frameCount++;
}
Exemplo n.º 6
0
void ImageBuffer::generatePerlin(Perlin &p)
{
	for(int row=0; row<_height; row++) for(int col=0; col<_width; col++)
	{
		// Grab a noise value for the pixel and shift range from [-1..1] to [0..1]
		float noise = 0.0f;

		vector<float> *octavesNoise = p.noise((float)col/_width, (float)row/_height, 0.0f);
		vector<float>::iterator i = octavesNoise->begin();
		while(i != octavesNoise->end())
		{
			noise += *i;
			i++;
		}
		delete octavesNoise;

		noise = (noise+1.0f)*0.5f;
			
		// Remember:						 x,									 y      (not row,col)
		setPixel(row, col, Colour(noise,noise,noise));
	}
}
Exemplo n.º 7
0
void ImageBuffer::warpPerlin(Perlin &p)
{
	// Make a copy of the current image buffer. This is used to preserve the original texture while the current texture is warped.
	ImageBuffer *newBuf = new ImageBuffer(_width, _height);
	memcpy(newBuf->getBuffer(), buffer, _width*_height*3*sizeof(float));

	for(int row=0; row<_height; row++) for(int col=0; col<_width; col++)
	{
		// Make some noise at current pixel
		float x = (float)col/_width;
		float y = (float)row/_height;

		//float noise = p.noise(x,y,0.0f)*0.13f;
		float noise = 0.0f;
		vector<float> *octavesNoise = p.noise(x,y,0.0f);
		vector<float>::iterator i = octavesNoise->begin();
		while(i != octavesNoise->end())
		{
			noise += *i;
			i++;
		}
		delete octavesNoise;

		noise *= 0.13f;

		// Find noisey pixel position. If noise pushes pixel position beyond image dimension, wrap around.
		int noiseCol = static_cast<int>(col + _width*noise);
		if(noiseCol > _width-1) noiseCol -= _width;
		else if(noiseCol < 0) noiseCol += _width;
		int noiseRow = static_cast<int>(row + _height*noise);
		if(noiseRow > _height-1) noiseRow -= _height;
		else if(noiseRow < 0) noiseRow += _height;

		// Set noisy pixel position from copied buffer to current buffer
		setPixel( row, col, newBuf->getPixel(_height-1-noiseRow, noiseCol) );
	}

	delete newBuf;
}
Exemplo n.º 8
0
void ImageBuffer::generatePerlinWood(Perlin &p)
{
	for(int row=0; row<_height; row++) for(int col=0; col<_width; col++)
	{
		float noise = 0.0f;

		vector<float> *octavesNoise = p.noise((float)col/_width, (float)row/_height, 0.0f);
		vector<float>::iterator i = octavesNoise->begin();
		while(i != octavesNoise->end())
		{
			noise += *i;
			i++;
		}
		delete octavesNoise;

		noise = (noise+1.0f)*7.0f;
		noise = noise - static_cast<int>(noise);
			
		// Remember:						 x,									 y      (not row,col)
		setPixel(row, col, Colour(noise,noise,noise));
	}
}
Exemplo n.º 9
0
void ImageBuffer::generatePerlinFlame(Perlin &p)
{
	for(int row=0; row<_height; row++) for(int col=0; col<_width; col++)
	{
		// Grab an absolute noise value [0..1], then invert
		float noise = 0.0f;

		vector<float> *octavesNoise = p.noise((float)col/_width, (float)row/_height, 0.0f);
		vector<float>::iterator i = octavesNoise->begin();
		while(i != octavesNoise->end())
		{
			noise += abs(*i);
			i++;
		}
		delete octavesNoise;

		// Invert
		noise = 1.0f - noise;
		noise = noise*noise;
			
		// Remember:						 x,									 y      (not row,col)
		setPixel(row, col, Colour(noise,noise,noise));
	}
}