Playing around with fluid simulation

Thank you very much for your reply! I am working on processing and haven’t changed the code much. It is quite long and I am thinking maybe it’s a little complicated for me to figure out how to get different fluid objects to interact.

But pixelflow seems very promising! If you have any suggestions on how I would go about changing colors in there it would be amazing. I have added another fluid object but can’t figure out how to get the color to change.


// FLUID SIMULATION EXAMPLE
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D;

// fluid simulation
DwFluid2D fluid;
DwFluid2D fluid2;

// render target
PGraphics2D pg_fluid;

public void setup() {
  size(800, 800, P2D);

  // library context
  DwPixelFlow context = new DwPixelFlow(this);

  // fluid simulation
  fluid = new DwFluid2D(context, width, height, 1);
  fluid2 = new DwFluid2D(context, width, height, 1);

  // some fluid parameters
  fluid.param.dissipation_velocity = 0.70f;
  fluid.param.dissipation_density  = 0.99f;
  
  fluid2.param.dissipation_velocity = 0.70f;
  fluid2.param.dissipation_density  = 0.99f;

  // adding data to the fluid simulation
  fluid.addCallback_FluiData(new  DwFluid2D.FluidData() {
    public void update(DwFluid2D fluid) {
      if (mousePressed) {
        float px     = mouseX;
        float py     = height-mouseY;
        float vx     = (mouseX - pmouseX) * +15;
        float vy     = (mouseY - pmouseY) * -15;
        fluid.addVelocity(px, py, 14, vx, vy);
        fluid.addDensity (px, py, 20, 0.0f, 0.4f, 1.0f, 1.0f);
        fluid.addDensity (px, py, 8, 1.0f, 1.0f, 1.0f, 1.0f);
      }
    }
  });
  
  
    fluid2.addCallback_FluiData(new  DwFluid2D.FluidData() {
    public void update(DwFluid2D fluid2) {
      if (keyPressed) {
        float px     = mouseX;
        float py     = height-mouseY;
        float vx     = (mouseX - pmouseX) * +15;
        float vy     = (mouseY - pmouseY) * -15;
        fluid.addVelocity(px, py, 14, vx, vy);
        fluid.addDensity (px, py, 20, 0.0f, 0.4f, 1.0f, 1.0f);
        fluid.addDensity (px, py, 8, 1.0f, 1.0f, 1.0f, 1.0f);
      }
    }
  });

  pg_fluid = (PGraphics2D) createGraphics(width, height, P2D);
}


public void draw() {    
  // update simulation
  fluid.update();
  fluid2.update();

  // clear render target
  pg_fluid.beginDraw();
  pg_fluid.background(0);
  pg_fluid.endDraw();

  // render fluid stuff
  fluid.renderFluidTextures(pg_fluid, 0);
  fluid2.renderFluidTextures(pg_fluid, 0);

  // display
  image(pg_fluid, 0, 0);
}

I can see it was sort of implemented in this example but I am having a hard time figuring out how:
https://github.com/diwi/PixelFlow/blob/master/examples/FlowField/FlowField_LIC_OpticalFlow/FlowField_LIC_OpticalFlow.java

Any advice is appreciated.
Thanks so much!