// add force and dye to fluid, and create particles void msaFluidParticlesApp::addToFluid( Vec2f pos, Vec2f vel, bool addColor, bool addForce ) { float speed = vel.x * vel.x + vel.y * vel.y * getWindowAspectRatio() * getWindowAspectRatio(); // balance the x and y components of speed with the screen aspect ratio if( speed > 0 ) { pos.x = constrain( pos.x, 0.0f, 1.0f ); pos.y = constrain( pos.y, 0.0f, 1.0f ); const float colorMult = 100; const float velocityMult = 30; if( addColor ) { Color drawColor( CM_HSV, ( getElapsedFrames() % 360 ) / 360.0f, 1, 1 ); fluidSolver.addColorAtPos( pos, drawColor * colorMult ); if( drawParticles ) particleSystem.addParticles( pos * Vec2f( getWindowSize() ), 10 ); } if( addForce ) fluidSolver.addForceAtPos( pos, vel * velocityMult ); if( ! drawFluid && getElapsedFrames()%5==0 ) fadeToColor( 0, 0, 0, 0.1f ); } }