From 2b02ccfe33fe8d02db1229c9b8c6e00c59684254 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Thu, 8 Dec 2022 18:43:21 +0000 Subject: [PATCH] add diffusion explanation to gdd --- gdd.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gdd.md b/gdd.md index 8ad3e5d..3c72c77 100644 --- a/gdd.md +++ b/gdd.md @@ -28,6 +28,27 @@ Add a tick counter as a UI element. Diffusing should use 'pull' operations; tiles should pull values from surrounding tiles. This is an attempt to think forwards to parallelising computation of diffusiong - ideally using the GPU. +#### Diffusion Algorithm + +Diffusion is modelled as two-dimensional steady-state heat conduction. +This means that the amount of a value does not change between the start and end of the computation of the diffusion step. +The value at one 2D location is calculated based on the values of itself and its neighbours in the previous step. +A diffusion coefficient controls the rate of diffusion. + +[Video explanation](https://www.youtube.com/watch?v=RGbV7T_iWT8) +[Derivation](https://www.tec-science.com/thermodynamics/heat/heat-equation-diffusion-equation/) + +Implementation: + +```cs +private float TransferHeat(float t0, float alpha, float nx, float ny, float px, float py) +{ + float d2tdx2 = nx - 2 * t0 + px; + float d2tdy2 = ny - 2 * t0 + py; + return t0 + alpha * (d2tdx2 + d2tdy2); +} +``` + ### Tile Types Tiles start as wild tiles.