Loading...
Logo
Processing Forum
Is there any way to change the background color of msafluid application ?

Replies(2)

Are you referring to the MSAFluidDemo ? 
If so, this should be in Contributed Libraries, as people will need that library in order to run any code... 
But your question I think is trying to determine where and which opengl function sets the background ?

I'm not quite sure, but it's to do with the blending... but you should post some code to where you think it is, so that people who dont have the sketch have a chance to comment properly... 
Ya I am talking about MSAFluidDemo application only.Its default background is black n i want to change it to some  other color but not getting how to do this I tried background() function in draw() function too but it shows the changed color only at the start of application n again the color turns back to black.
Here is the some part of code:
////////////////////////////////////////////////////////////////
import msafluid.*;
//import fullscreen.*;
import processing.opengl.*;
import javax.media.opengl.*;

final float FLUID_WIDTH = 120;

float invWidth, invHeight;    // inverse of screen dimensions
float aspectRatio, aspectRatio2;

MSAFluidSolver2D fluidSolver;

ParticleSystem particleSystem;

PImage imgFluid;

boolean drawFluid = true;
//FullScreen fs;
void setup()
{
    size(1024,768,OPENGL);    // use OPENGL rendering for bilinear filtering on texture
    //    size(screen.width * 49/50, screen.height * 49/50, OPENGL);
    hint( ENABLE_OPENGL_4X_SMOOTH );    // Turn on 4X antialiasing
  //  fs = new FullScreen(this);
   // fs.enter();
    invWidth = 1.0f/width;
    invHeight = 1.0f/height;
    aspectRatio = width * invHeight;
    aspectRatio2 = aspectRatio * aspectRatio;

    // create fluid and set options
    fluidSolver = new MSAFluidSolver2D((int)(FLUID_WIDTH), (int)(FLUID_WIDTH * height/width));
    fluidSolver.enableRGB(true).setFadeSpeed(0.3).setDeltaT(0.03).setVisc(0.001);
     background(0,120,234);
    // create image to hold fluid picture
    imgFluid = createImage(fluidSolver.getWidth(), fluidSolver.getHeight(), RGB);

    // create particle system
    particleSystem = new ParticleSystem();

    // init TUIO
    initTUIO();
}


void draw()
{
    background(0,120,234);  //even doing this does not work
    updateTUIO();
    fluidSolver.update();

     for(int i=0; i<fluidSolver.getNumCells(); i++)
        {
            int d = 2;
            imgFluid.pixels[i] = color(fluidSolver.r[i] * d, fluidSolver.g[i] * d, fluidSolver.b[i] * d);
        } 
    background(0,120,234); 
   
    imgFluid.updatePixels();    
    image(imgFluid, 0, 0, width, height);
    particleSystem.updateAndDraw();
}

// add force and dye to fluid, and create particles
void addForce(float x, float y, float dx, float dy)
{
   // balance the x and y components of speed with the screen aspect ratio
    float speed = dx * dx  + dy * dy * aspectRatio2;
    if(speed > 0)
    {
        if(x<0)
           x = 0;
        else if(x>1)
            x = 1;
        if(y<0)
           y = 0;
        else if(y>1)
              y = 1;

        float colorMult = 5;
        float velocityMult = 50.0f;

        int index = fluidSolver.getIndexForNormalizedPosition(x, y);

        color drawColor;

        colorMode(HSB, 360, 1, 1);
        float hue = ( (x+y)*180 ) % 360;
        // float saturation = (x*90)%360;
         // float brightness = (y*90)%360;
        drawColor = color(hue,1,1);
        colorMode(RGB, 1); 

        fluidSolver.rOld[index]  += red(drawColor) * colorMult;
        fluidSolver.rOld[index]  += (drawColor>> 16 & 0xFF) *colorMult;
        fluidSolver.gOld[index]  += green(drawColor) * colorMult;
        fluidSolver.bOld[index]  += blue(drawColor) * colorMult;
        particleSystem.addParticles(x * width, y * height, 10);
        fluidSolver.uOld[index] += dx * velocityMult;
        fluidSolver.vOld[index] += dy * velocityMult;
    }
}
///////////////////////////////////////////////////////////////////////////////

If anyone have any idea then please suggest me how to do this.