I'm creating a game which has around 3000 particles that fall into a pile. The particles are each a pixel and i just use a boolean[][] to set and check which pixel is clear. Right now i am using this code
if (!isFalling(m)) {
if (isClear(getX() + 1, getY()) && isClear(getX() + 1, getY() - 1))
setX(getX() + 1);
else if (isClear(getX() - 1, getY()) && isClear(getX() - 1, getY() - 1)
setX(getX() - 1);
}
the problem is that this code gives me a very strict pyramid shape which doesnt look very natural. I want it to look something like salt would if you poured it into a pile. My question is, does anyone know of an algorithm or a better way to simulate particle piles? Any help would be greatly appreciated.
Solution: I have found a nice article here
You've taken on a big task :) It's not just how to calculate and draw the particles, it's the physics which describe how they should move.
Take a look at this for a starter:
http://www.daniweb.com/software-development/java/threads/426676/sand-game-problem-with-graphics
When Googling, try "particle generator" or "particle emitter".
Also see this question:
How do those java sand games keep track of so many particles?
The main thing you might be missing is to add randomness, some entropy, into your system.