Actually my way does get around your problem to some degree but not quite in the way you suggest or possibly as efficiently.
What I was concerned about was making sure there were no net gains or losses of stuff in the entire grid.
Here is roughly how it works for a grid
1 . 2 . 3
4 . 5 . 6
7 . 8 . 9
Starting at cell 1, the program compares the value with 2 and 4. If there is a big enough difference then modifications are made otherwise nothing is done at all.
If the value in 2 is greater than that in 1 then a certain proportion of the difference is removed from 2 and stored temporarily in an independent variable.
next the value in 1 is compared to 4 and again if the difference is above a certain threshold, a portion of the difference is removed from 4 and added to the temporary store.
Once all neighboring cells have been checked, the temporary store value is added to cell 1
Then we move on to cell 2 and repeat.
In this method we are double checking cells that may have already been the central cell but changes will only be made if the value in that cell is bigger than the one in the present cell. In actuality I have never seen the value shared back again from cell 1 to cell 2.
At the end of the entire grid scan I inserted a check sum (not there in the present code) to see what the total was and it always stayed the same so I am happy that the math part is working.
I tried going the other way with each cell pushing its excess to the others in equal ammounts at first but that didn't work so well.
Using another layer of the grid to store changes and then adding them back in was one possible option to use but it would have meant scanning the grid twice to update the values. My way was a compromise that allowed for faster code.
here is the code for the grid updating (to save you looking for it)
Public Sub RefreshGrid(z As Integer)
Dim Change As Single
Dim tot As Single
Dim val As Single
Dim Threshold As Integer
Threshold = 3
Change = 1
For xx = 0 To 120
For yy = 0 To 90
val = grid(xx, yy, z)
tot = 0
If xx < 90 Then
If grid(xx + 1, yy, z) - val > Threshold Then
grid(xx + 1, yy, z) = grid(xx + 1, yy, z) - Change
tot = tot + Change
End If
End If
If xx > 0 Then
If grid(xx - 1, yy, z) - val > Threshold Then
grid(xx - 1, yy, z) = grid(xx - 1, yy, z) - Change
tot = tot + Change
End If
End If
If yy < 90 Then
If grid(xx, yy + 1, z) - val > Threshold Then
grid(xx, yy + 1, z) = grid(xx, yy + 1, z) - Change
tot = tot + Change
End If
End If
If yy > 0 Then
If grid(xx, yy - 1, z) - val > Threshold Then
grid(xx, yy - 1, z) = grid(xx, yy - 1, z) - Change
tot = tot + Change
End If
End If
grid(xx, yy, z) = grid(xx, yy, z) + tot
Next yy
Next xx
End Sub
z represents the grid level to be scanned.
As you can see I only scan one layer at a time so that the program doesn't take such a speed hit. I tried doing all the layers and it pretty much stopped the program dead in its tracks. 20 cycles per second became 1 cycle.
Believe me when I say this stuff is extremely processor intensive.
:D PY :D