I have a simple program, her heart is a two-dimensional array of floats, presumably representing gas concentrations. I tried to come up with a simple algorithm that would simulate a gas expanding outward like a cloud, ending up with the same gas concentration throughout the grid.
For example, a given state progression could be: (using ints for simplicity)
initial state
00000
00000
00900
00000
00000
after 1 pass of the algorithm
00000
01110
01110
01110
00000
another pas should give a 5x5 grid containing a value of 0.36 (9/25).
I tried this on paper, but no matter how hard I try, I can't get around the algorithm to do this.
So my question is: how should I try to code this algorithm? I tried several things, using convolution, trying to take each grid cell in turn and distribute its neighbors, but they all turn out to have undesirable effects, such as, in the end, with less gas than I originally started, or all the gas movements are in one direction rather than expanding outward from the center. I really can't get around it at all and would appreciate any help.
RichardBennet
source share