Patrick Matte Creative Coder

Fluid simulation with physics

I created a quick prototype of a realtime liquid simulation for a project over at Chiat a couple weeks ago. The result might not be very realistic, a little cartoony you might say, but it’s definitely fun to play with (any program that features real-time physics just fascinates me). I made a quick demo to show you how it’s done.

I took a look at some reviews to choose the physics engine I would use and APE seemed to be the easiest one. It was pretty simple indeed as I was able to build my original demo in a single day.

It was a little tricky to create the physics bottle that would hold the particles. The easiest way I found was to put movieclips on stage in the shape of the bottle and loop through each pieces and create a corresponding APE RectangleParticule. The tricky part is that when you rotate a movieclip in Flash, the height and width of the clip changes, so i had to nest a movieclip within to be able to read the correct height and width of the particle.

Download the source

22 comments on “Fluid simulation with physics”

  1. Excellent ! nostalgie de la prog … beau résultat… en ligne bientôt?

  2. Holy Moly!
    this is genious!
    I would have never thought it was so simple to generate the look of fluids…
    have you tested to check if the process is heavy on crappy computers?

  3. WOW…. guy… the simplest but perfect idea… wow… just… wow… this is so complete… wonderful idea…

  4. Hi Patrick,
    Just had a look at the code. It works really well fair play.
    I’m just wondering if you know of a way to change the direction of the gravity?
    I’d like to be able to change the angle as I use the application…

    Thanks

  5. Hi JC, I’m not sure, you could check APE’s documentation, there might be a vector somewhere that you can set for the gravity.

  6. Do you know of anyone that has tried to implement something similar to your liquid demo in Sprite Kit using SWIFT?

    I am just getting started as a developer and I would love to figure out how to do this. One part in particular I don’t know what to do with is this:

    “apply threshold on bitmapdata to get hard edges”

    I have tried to Google how that would be done in Sprite Kit but have not been able to find any answers.

Comments are closed.