05
Dec
04

### Fire Animation

Fire Animation – adapted from Terry Robb’s Mathematica notebook. This texture is randomly generated to look like fire. It is not a model of real fire.
```(* runtime: 10 minutes *) n = 275; m = 14; SeedRandom[0]; noise = Table[Random[], {m}]; Fire[x_, y_, t_] := Module[{x2, y2, i, j, cx, cy, vx, vy, k, z = 0.0}, Do[x2 = 2^l(4.0 x - 0.01t); y2 = 2^l (2.0y - 0.1t); j = Floor[x2]; i = Floor[y2]; cx = (3 - 2(x2 - j))(x2 - j)^2; cy = (3 - 2(y2 - i))(y2 - i)^2; k = Floor[2^15 noise[[Mod[i, m] + 1]]]; vx = noise[[Mod[j + k, m] + 1]]; vy = vx + cx(noise[[Mod[j + 1 + k, m] + 1]] - vx); k = Floor[2^15 noise[[Mod[i + 1, m] + 1]]]; vx = noise[[Mod[j + k, m] + 1]]; z += Abs[vy + cy(vx + cx(noise[[Mod[j + 1 + k, m] + 1]] - vx) - vy) - 0.5]/2^l, {l, 0, 4}]; z - 0.5y]; Table[DensityPlot[Fire[x, y, t], {x, 0, 1}, {y, 0, 1}, PlotPoints -> n, Mesh -> False, Frame -> False], {t, 0, 15}];```

Here is some code to find fire color as a function of temperature. You can read more about this on Hugo Elias’ website and Henrik Jensen’ website.
```h = 6.62606876*^-34; c = 299792458; k = 1.380658*^-23; nm = 10^-9; FireColor[T_] := RGBColor @@ Map[Max[0, Min[1, 1 -Exp[-50*2.67253*^-13If[T < 50, 0, 2Pi h c^2/(#^5(E^(h c/(k T #)) - 1))]]]] &, {700nm, 560nm, 470nm}]; DensityPlot[x, {x, 0, 1}, {y, 0, 1/6}, AspectRatio -> Automatic, PlotPoints -> {275, 2}, Mesh -> False,Frame -> False, ColorFunction -> (FireColor[6023#] &)];```

## Welcome !

You will find here some of my favorite hobbies and interests, especially science and art.

I hope you enjoy it!

Subscribe to the RSS feed to stay informed when I publish something new here.

I would love to hear from you! Please feel free to send me an email : bugman123-at-gmail-dot-com