Full Smoke Solver
A smoke solver written in processing, based on the 2003 Real Time Fluid Dynamics for Games paper by Jos Stam
HTML
<script type="application/processing" data-processing-target="pjs">
//-*****************************************************************************
// Copyright (c) 2011-2013 Christopher Jon Horvath. All rights reserved.
//-*****************************************************************************
//-*****************************************************************************
//-*****************************************************************************
// GLOBAL VARIABLES (SIMULATION PARAMETERS)
//-*****************************************************************************
//-*****************************************************************************
// Grid resolution per side. Rectangular
int NX = 120;
int NY = 120;
// The size of the sim, in "world" units.
float LX = 100.0;
// Size, in "world" units, of a grid cell.
// Our cells are uniform (square) so DX & DY are the same.
float DXY = LX / ( float )NX;
// Y size, keeping square cells.
float LY = DXY * ( float )NY;
// The size of each grid cell, in pixels.
// This is for drawing
int CellPixels = 8;
// The rate at which we inject density
// into the grid by painting with the
// mouse.
float EmissionRate = 2.0;
float DenEmissionRadius = 15.0;
float VelEmissionRadius = 20.0;
// The rate at which density
// diffuses (dissipates)
float D_viscosity = 0.00001;
// The rate at which velocity
// dissipates
float V_viscosity = 0.00001;
// The rate at which density decays.
float D_damp = 0.01;
// The rate at which velocity decays.
float V_damp = 0.0001;
// Our time step
float DT = 1.0;
// A scale on input velocity
float Vscale = 0.75;
// Our Window will be made of "gridRes" cells,
// where each cell is "cellSize" pixels big.
int WindowWidth = NX * CellPixels;
int WindowHeight = NY * CellPixels;
// Our simulation grids (Our State) will be one cell larger in each
// dimension to accomodate boundary conditions.
int GX = NX+2;
int GY = NY+2;
// The length of all of our (one-dimensional)
//...