void Particle::update(const Perlin &perlin) { // get Perlin noise value based on my location and // elapsed seconds and turn this noise value into an angle. float nX = mLoc.x * 0.005f; float nY = mLoc.y * 0.005f; float nZ = app::getElapsedSeconds() * 0.1f; float noise = perlin.fBm( nX, nY, nZ ); float angle = noise * 15.0f; Vec3f noiseVector( cos( angle ), sin (angle), cos(angle)); mVel += noiseVector * 0.3f * ( 1.0f - mAgePercentage ); mLoc += mVel; mVel *= mDecay; if (mLoc.x > 0 && mLoc.x < getWindowWidth() ) { mXPercentage = (float) mLoc.x / (float) getWindowWidth(); } if (mLoc.y > 0 && mLoc.y < getWindowWidth() ) { mYPercentage = (float) mLoc.y / (float) getWindowHeight(); } if (mAge > mLifespan) { mIsDead = true; } else { mAge++; mAgePercentage = (float) mAge / (float) mLifespan; } }
void svvimApp::update() { float noise = mPerlinGenerator.fBm(Vec2f(0., app::getElapsedSeconds())); app::console() << noise << "\n"; // Update alpha values getAlpha(); if (mPoolWaterMovie) mMaskTexture = mPoolWaterMovie.getTexture(); if (mCurrentMovie.isDone()) { incrementMovie(); } app::console() << 10 * app::getElapsedSeconds() << "\n"; mImageTexture = mCurrentMovie.getTexture(); //mImageTexture = mCurrentBgTexture; // ... }
void Particle::Step(float pElapsed, const Perlin &pNoise) { Age--; if (Age>0) { PAlpha = math<float>::min(1, ((float)Age * 0.5f * (float)Age) / (float)mLifeSpan); PPosition.y += mVelocity.y; float cNoise = pNoise.fBm(vec3(PPosition.x*0.005f, PPosition.y*0.01f, PPosition.z*0.005f)); float cAngle = cNoise*15.0f; PPosition.x += (cos(cAngle)*mVelocity.x*(1.0f-PAlpha))*0.1f; PPosition.z += (sin(cAngle)*mVelocity.z*(1.0f - PAlpha))*0.1f; mVelocity.x *= 1.001f; mVelocity.y *= .99999f; mVelocity.z *= 1.001f; float elapsedFrames = pElapsed; //PModelMatrix = mat4(); //PModelMatrix = glm::rotate(PModelMatrix, mRotSpeed *elapsedFrames* 0.2f, vec3(0, 0, 1)); //PModelMatrix = glm::rotate(PModelMatrix, mRotSpeed *elapsedFrames* 0.2f, vec3(1, 0, 0)); //PModelMatrix = glm::rotate(PModelMatrix, mRotSpeed *elapsedFrames* 0.2f, vec3(0, 1, 0)); //PModelMatrix = glm::translate(PModelMatrix, PPosition); } }
void Corrdinate_spacesApp::update() { vector<Vec3f> positions; positions.resize(4); for( int i=0;i<positions.size();i++ ){ Perlin p; positions[i] = 3. * ( p.dnoise( getElapsedSeconds()+i, getElapsedSeconds()+i*2, getElapsedSeconds() ) * 2 - Vec3f(1.,1.,1.) ); } mVboMesh->bufferPositions(positions); mVboMesh->unbindBuffers(); }
void BasicParticleApp::update() { mAnimationCounter += 10.0f; // move ahead in time, which becomes the z-axis of our 3D noise // Save off the last position for drawing lines for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) partIt->mLastPosition = partIt->mPosition; // Add some perlin noise to the velocity for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) { vec3 deriv = mPerlin.dfBm( vec3( partIt->mPosition.x, partIt->mPosition.y, mAnimationCounter ) * 0.001f ); partIt->mZ = deriv.z; vec2 deriv2 = normalize( vec2( deriv.x, deriv.y ) ); partIt->mVelocity += deriv2 * SPEED; } // Move the particles according to their velocities for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) partIt->mPosition += partIt->mVelocity; // Dampen the velocities for the next frame for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) partIt->mVelocity *= CONSERVATION_OF_VELOCITY; // Replace any particles that have gone offscreen with a random onscreen position for( list<Particle>::iterator partIt = mParticles.begin(); partIt != mParticles.end(); ++partIt ) { if( isOffscreen( partIt->mPosition ) ) *partIt = Particle( vec2( Rand::randFloat( getWindowWidth() ), Rand::randFloat( getWindowHeight() ) ) ); } }
int generateTexture2D(char *framebuffer, int width, int height, char* imagePx) { GzColor textureColor = { 0, 0, 0 }; int finalColor[] = { 0, 0, 0 }; char *copybuffer = framebuffer; Perlin *per = new Perlin(4, 6.5, 0.5, 10); for (float x = 0; x < 256; x += 1) { for (float y = 0; y < 256; y += 1) { float noise = per->Get(x, y); //float noise = perlin_type1_2D(x, y); textureColor[RED] = finddensity(y, x, 256, 256, noise, 145); textureColor[GREEN] = finddensity(y, x, 256, 256, noise, 145); //textureColor[RED] = noise; //textureColor[GREEN] = noise; textureColor[BLUE] = 0.8; finalColor[RED] = (int)(textureColor[RED] * 255); finalColor[GREEN] = (int)(textureColor[GREEN] * 255); finalColor[BLUE] = (int)(textureColor[BLUE] * 255); if (finalColor[RED] > 255) finalColor[RED] = 255; if (finalColor[RED] < 0) finalColor[RED] = 0; if (finalColor[GREEN] > 255) finalColor[GREEN] = 255; if (finalColor[GREEN] < 0) finalColor[GREEN] = 0; if (finalColor[BLUE] > 255) finalColor[BLUE] = 255; if (finalColor[BLUE] < 0) finalColor[BLUE] = 0; *(framebuffer++) = (char)(finalColor[RED]); *(framebuffer++) = (char)(finalColor[GREEN]); *(framebuffer++) = (char)(finalColor[BLUE]); } } return 0; }
void cApp::setup(){ setWindowPos( 0, 0 ); setWindowSize( mW*0.5, mH*0.5 ); mExp.setup( mW*mScale, mH*mScale,0, 2999, GL_RGB, mt::getRenderPath() ); mPln.setOctaves(4); mPln.setSeed(1332); randSeed( mt::getSeed() ); int count = 0; for( int i=0; i<100; i++){ StrangeAgent sa; sa.setRandom(); mSAs.push_back( sa ); for(int j=0; j<sa.points.size(); j++){ mPlnPts.push_back( Vec3f(count*scale,0,0) ); count++; } } total = count; if( 1 ){ CameraPersp cam; cam.setNearClip(0.1); cam.setFarClip(1000000); cam.setFov(60); cam.setEyePoint( Vec3f(0,0,-30 ) ); cam.setCenterOfInterestPoint( Vec3f(0,0,0) ); cam.setAspectRatio( (float)mW/mH ); mCamUi.setCurrentCam(cam); }else{ ortho.setNearClip(0.1); ortho.setFarClip(1000000); ortho.setEyePoint( Vec3f(0,0,-7 ) ); ortho.setCenterOfInterestPoint( Vec3f(0,0,0) ); ortho.setAspectRatio( (float)mW/mH ); } #ifdef RENDER mExp.startRender(); #endif }
unsigned int TextureLoader::CreateNoiseTexture(double alpha, double beta, int n, int side) { Perlin perlin; float* data = new float[side*side*side]; double step = 1.0/(side-1.0); int index = 0; for (double x = 0; x <= 1; x += step) { for (double y = 0; y <= 1; y += step) { for(double z = 0; z <= 1; z += step) { float noise = static_cast<float>(perlin.PerlinNoise3D(x, y, z, alpha, beta, n)); data[index] = noise; index++; } } } //create the OpenGL texture unsigned int gl_texture_object; glGenTextures(1, &gl_texture_object); glBindTexture(GL_TEXTURE_3D, gl_texture_object); //filtering glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); float maxAnisotropy; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy); //when we work with textures of sizes not divisible by 4 we have to use the line reader //which loads the textures in OpenGL so as it can work with a 1 alligned memory (default is 4) //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //Generates texture glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, side, side, side, 0, GL_RED, GL_FLOAT, data); //eliminates the array from the RAM delete data; //creates the mipmap hierarchy glGenerateMipmap(GL_TEXTURE_3D); //returns the texture object return gl_texture_object; }
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++; }
void cApp::setup(){ setWindowPos( 0, 0 ); float w = 1920; float h = 1080*3; setWindowSize( w*0.2, h*0.2 ); mExp.setup( w, h, 0, 550-1, GL_RGB, mt::getRenderPath(), 0); cam = CameraPersp(w, h, 55.0f, 0.1, 1000000 ); if(0){ cam.lookAt( vec3(0,0,800), vec3(0,0,0) ); cam.setLensShift( 0,0 ); }else{ cam.setNearClip(0.100000); cam.setFarClip(1000000.000000); cam.setAspectRatio(0.592593); cam.setFov(55.000000); cam.setEyePoint(vec3(326.924622,-381.081604,259.431519)); cam.setWorldUp(vec3(0.000000,1.000000,0.000000)); cam.setLensShift(vec2(0.000000,0.000000)); cam.setViewDirection(vec3(-0.578462,0.674288,-0.459040)); cam.lookAt(vec3(326.924622,-381.081604,259.431519)+vec3(-0.578462,0.674288,-0.459040)); } camUi.setCamera( &cam ); mPln.setSeed(123); mPln.setOctaves(4); for( int i=0; i<6; i++){ Ramses r(eSimType,i); rms.push_back( r ); } makeGui(); #ifdef RENDER mExp.startRender(); #endif }
void TerrainApp::addQuad( int x, int y ) { Vec2f p00( x, y ); Vec2f p10( x + 1, y ); Vec2f p11( x + 1, y + 1 ); Vec2f p01( x, y + 1 ); float zScale = mHeight; float noiseScale = mNoiseScale; float z00 = zScale * mPerlin.fBm( p00 * noiseScale ); float z10 = zScale * mPerlin.fBm( p10 * noiseScale ); float z11 = zScale * mPerlin.fBm( p11 * noiseScale ); float z01 = zScale * mPerlin.fBm( p01 * noiseScale ); size_t idx = mTriMesh.getNumVertices(); // positions Vec3f t00( p00.x - xSize / 2., z00, p00.y - ySize / 2. ); Vec3f t10( p10.x - xSize / 2., z10, p10.y - ySize / 2. ); Vec3f t11( p11.x - xSize / 2., z11, p11.y - ySize / 2. ); Vec3f t01( p01.x - xSize / 2., z01, p01.y - ySize / 2. ); mTriMesh.appendVertex( t00 ); mTriMesh.appendVertex( t10 ); mTriMesh.appendVertex( t01 ); mTriMesh.appendVertex( t10 ); mTriMesh.appendVertex( t11 ); mTriMesh.appendVertex( t01 ); // normals Vec3f n0 = ( t10 - t00 ).cross( t10 - t01 ).normalized(); Vec3f n1 = ( t11 - t10 ).cross( t11 - t01 ).normalized(); mTriMesh.appendNormal( n0 ); mTriMesh.appendNormal( n0 ); mTriMesh.appendNormal( n0 ); mTriMesh.appendNormal( n1 ); mTriMesh.appendNormal( n1 ); mTriMesh.appendNormal( n1 ); mTriMesh.appendTriangle( idx, idx + 1, idx + 2 ); mTriMesh.appendTriangle( idx + 3, idx + 4, idx + 5 ); }
///Initializes the image by performing all perlin, mesh, heightmap, and other calls that generate the terrain. void init(){ glfwEnable(GLFW_KEY_REPEAT); ///--- Initializes the Perlin noise texture ///--- Initializes the fBm texture ///--- Sets background color glClearColor(/*gray*/ .8,.8,.8, /*solid*/1.0 ); glEnable(GL_DEPTH_TEST); ///--- Initlializes the terrain quad mesh (?takes the fBm as an input for displacing the height of vertices?) quad.init(perlin.init()); }
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(); }
void cApp::setup(){ setFrameRate( 25 ); setWindowPos( 0, 0 ); setWindowSize( mW*mScale, mH*mScale ); mExp.setup( mW*mScale, mH*mScale, 0, 2999, GL_RGB, mt::getRenderPath() ); mPln.setOctaves( 3 ); mPln.setSeed( 551 ); mt::loadColorSample("img/Mx80_2_org_B.jpg", mColorSample1 ); mt::loadColorSample("img/Mx80_2_org_B.jpg", mColorSample2 ); { // Audio Setup auto ctx = audio::Context::master(); audio::DeviceRef device = audio::Device::getDefaultOutput(); audio::Device::Format format; format.sampleRate( 192000 ); format.framesPerBlock( mFpb ); device->updateFormat( format ); cout << "--- Audio Setting --- " << endl; cout << "device name : " << device->getName() << endl; cout << "Sample Rate : " << ctx->getSampleRate() << endl; cout << "frames per Block : " << ctx->getFramesPerBlock() << endl; mWaves.assign( 7, Wave() ); for( int i=0; i<mWaves.size(); i++ ){ mWaves[i].create( "snd/test/3s1e_192k_" + toString(i+1)+ ".wav" ); } ctx->enable(); } #ifdef RENDER mExp.startRender(); #endif }
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; } } } }
float getHeight(int x, int y) { float height = static_cast<float>(perlinNoise.GetValue(static_cast<double>(x) / perlinFrequency, 0.5, static_cast<double>(y) / perlinFrequency)) + 1.0f; height /= 2.0f; float distanceFromOrigin = static_cast<float>(Vector2i(x - halfMapSize, y - halfMapSize).getMagnitude()); float fractionFromOrigin = (1.0f - distanceFromOrigin / static_cast<float>(halfMapSize)); height *= fractionFromOrigin * peakAmplitude; height += fractionFromOrigin * peakHeight - peakAmplitude; return height; }
void copyNoiseToHeightmap(Perlin& pn, RECT rc, HeightMap<T>* pHMap, int tMax) { int x,y; float xStep = 1.0f/(rc.right-rc.left); float yStep = 1.0f/(rc.bottom-rc.top); //Perlin产生的值域在[-振幅,+振幅]之间 //--缩放到0-255的区间 float offset = pn.GetAmplitude(); float range = pn.GetAmplitude()*2; for(y=rc.top; y<rc.bottom; y++) { for(x=rc.left; x<rc.right; x++) { float n = pn.Get(x*xStep, y*yStep); T tn = T((n+offset)/range*tMax); pHMap->setValue(x, y, tn); } }//endof for }
void FurPoint::update(const Perlin &perlin, float stepX, float stepY, float stepZ){ if (1.0f - age / lifetime <= 0.0f) isDead = true; if (position.x < 0 || position.x > getWindowWidth()) isDead = true; if (position.y < 0 || position.y > getWindowHeight()) isDead = true; noiseFloat = perlin.fBm( position.x * stepX, position.y * stepY, getElapsedFrames() * stepZ ); noiseVec.x = cos(((noiseFloat) * M_PI_2) * 10.0f); noiseVec.y = sin(((noiseFloat) * M_PI_2) * 10.0f); velocity += noiseVec; velocity *= 0.5f; position += velocity; age++; }
void Water::createHeightMap(){ Perlin noise = Perlin(40); float channelSize = 400 ; cout << "Creating water height map - " << endl ; Channel heightMapChannel = Channel8u(channelSize, channelSize); Channel::Iter iter = heightMapChannel.getIter( heightMapChannel.getBounds()); float max_value = -1.0 ; float min_value = 10001.0 ; while(iter.line()){ while(iter.pixel()){ Vec2f current = iter.getPos(); float value = 255.0F * noise.fBm(5 * current.x/channelSize, 5 * current.y/channelSize); if( value > max_value){ max_value = value ; } if( value < min_value){ min_value = value ; } } } iter = heightMapChannel.getIter( heightMapChannel.getBounds()); while(iter.line()){ while(iter.pixel()){ Vec2f current = iter.getPos(); float value = 255.0f * noise.fBm(5 * current.x/channelSize, 5 * current.y/channelSize); value = 255.0f * (value - min_value) / (max_value - min_value); iter.v() = value ; } } heightMap = gl::Texture(heightMapChannel); cout << min_value << " " << max_value << endl ; cout << "Done creating water height map" << endl; }
void BasicParticleApp::setup() { mPerlin.setSeed( clock() ); mAnimationCounter = 0; for( int s = 0; s < NUM_INITIAL_PARTICLES; ++s ) mParticles.push_back( Particle( Vec2f( Rand::randFloat( getWindowWidth() ), Rand::randFloat( getWindowHeight() ) ) ) ); CONSERVATION_OF_VELOCITY = 0.9f; SPEED = 5.0f; // Turn on additive blending gl::enableAlphaBlending(); }
void cApp::setup(){ mPln.setSeed( 345 ); mPln.setOctaves( 4 ); openDir(); fs::path path = dir/("f_00000.png"); sur = Surface8u( loadImage( path) ); int w = sur.getWidth(); int h = sur.getHeight(); pcam = CameraPersp(w, h, 50, 1, 10000); camUi.setCamera( &pcam ); mExp.setup( w, h, 0, 3000-1, GL_RGB, mt::getRenderPath(), 0 ); setWindowSize( w*0.5, h*0.5 ); setWindowPos(0, 0); #ifdef RENDER mExp.startRender(); #endif }
void cApp::setup(){ setWindowPos( 0, 0 ); float w = 1920; float h = 1080; setWindowSize( w*0.6, h*0.6 ); mExp.setup( w, h, 0, 1000, GL_RGB, mt::getRenderPath(), 0 ); cams.assign(6, CameraPersp()); camUis.assign(6, CameraUi()); for( int i=0; i<6; i++){ cams[i] = CameraPersp(w, h, 55.0f, 1, 100000 ); cams[i].lookAt( eye, vec3(0,0,0) ); int col = i%3; int row = i/3; cams[i].setLensShift( -0.666+0.666*col, -0.5+row*1.0); camUis[i].setCamera( &cams[i] ); } mPln.setSeed(123); mPln.setOctaves(4); for( int i=0; i<6; i++){ rms.push_back( Ramses(simType,i) ); } makeGui(); #ifdef RENDER mExp.startRender(); #endif }
void Particle::update(float delta, Perlin &perlin) { const float noise = perlin.fBm(mPosition * 0.005f + app::getElapsedSeconds() * Vec3f(0.1f, 0.1f, 0.1f)); const float angle = noise * 15.0f; mVelocity += 0.1f * Vec3f(cos(angle), sin(angle) - 0.3f, 2.0f * sin(angle) - 0.5f); mPosition += delta * mVelocity; mVelocity *= mVecolityDecay; mAge += 1; // flap if (mAge >= mLifespan) { mIsDead = true; } }
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; }
void DelayFeedback::addSplash( const Vec2f &pos ) { mSplashes.push_back( Splash() ); auto &splash = mSplashes.back(); splash.mCenter = pos; splash.mAlpha = 1; float radiusMin = ( 1 - (float)pos.y / (float)getWindowHeight() ) * MAX_RADIUS / 2; splash.mRadius = randFloat( radiusMin, 30 ); float endRadius = randFloat( MAX_RADIUS * 0.9f, MAX_RADIUS ); timeline().apply( &splash.mRadius, endRadius, 7, EaseOutExpo() ); timeline().apply( &splash.mAlpha, 0.0f, 7 ); float h = math<float>::min( 1, mPerlin.fBm( pos.normalized() ) * 7.0f ); splash.mColorHsv = Vec3f( fabsf( h ), 1, 1 ); }
void Particle::update( const Perlin &perlin, const Channel32f &channel, const ivec2 &mouseLoc ) { // get Perlin noise value based on my location and // elapsed seconds and turn this noise value into an angle. float nX = mLoc.x * 0.005f; float nY = mLoc.y * 0.005f; float nZ = app::getElapsedSeconds() * 0.1f; float noise = perlin.fBm( nX, nY, nZ ); float angle = noise * 15.0f; vec2 noiseVector( cos( angle ), sin( angle ) ); mVel += noiseVector * 0.2f * ( 1.0f - mAgePer ); mLoc += mVel; mVel *= mDecay; mRadius = mScale * mAgePer; mAge++; if( mAge > mLifespan ) mIsDead = true; mAgePer = 1.0f - ( (float)mAge/(float)mLifespan ); }
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)); } }
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; }
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)); } }
void cApp::update(){ if( !bStart ) return; gl::VboMesh::VertexIter vitr( mPoints ); for(int i=0; i<mPoints.getNumVertices(); i++ ){ Vec3f &pos = ps[i]; int x = pos.x; int y = pos.y; x = cinder::math<int>::clamp( x, 0, intensityW-1 ); y = cinder::math<int>::clamp( y, 0, intensityH-1 ); Vec3f vel( mVecMap[x][y].x, mVecMap[x][y].y, 0); Vec3f noise = mPln.dfBm(x, y, cs[i].a ) * 0.2; mVelocity[i] = mVelocity[i] + (vel + noise); vitr.setPosition( pos + mVelocity[i] ); vitr.setColorRGBA( cs[i] ); ++vitr; } }