Fluids are really cool and also very common - they're all around you! The human body is 65% water, and the Earth is 2/3 water.. while gasses are like fluids brother - they have a very similar set of properties - like air, smoke and clouds.
If you drop in in water or watch smoke float up into the sky - I'm sure you noticed the patterns of similarity?
Anyhow, fluid and gas dynamics are all around you! The're magical and beautiful - and you can emulate their characteristics in code.
So how do you go about simulating these things? Is it hard?
Well fluid dynamics is a big area! With lots of different models - with levels of accuracy and computation cost - however, for the most part of this tutorial I'll focus on `visually' realistic simulations that make numerical approximations. Looks and moves correctly! Also fast and we can interact with it in real-time.
Fluids and gases are everywhere! They're inside you, they're all around you, they are both simple and complex. Their beauty and magic in static and dynamic form are beyond words.
Few concepts and their details - which we're going to try and include:
• Diffusion: In a cup of tea, sugar molecules diffuse from areas of high concentration to low concentration, sweetening the drink evenly.
• Vortex: A whirlpool forms when water rushes down a drain, creating a swirling vortex of water.
• Buoyancy: A ship floats because its weight is less than the weight of water it displaces, thanks to buoyancy.
• Viscosity: Honey flows slowly due to its high viscosity, resisting deformation and sticking to surfaces.
Simple Discrate Fluid/Gas Simulation Demo
The code uses JavaScript for the fluid/gas dynamics - as it's easy to follow and can run anywhere (just need a web browser). Focus on 2D simulations - so that it doesn't get overy complex. But it should be enough to show swirly ink-like animation patterns.
The concept implementation has been broken down into key functions - each performing a specific task (like diffusion and buoyancy).
The full code is also implemented on a demo page (LINK).