I have a suggestion for sand. Make the particles move left or right if the one below doesn't have anything to the left or right.
Gravity is ambitious. I would think about trying to keep the code that controls behavior completely separate from the stuff that displays it so that you can easily switch how you're rendering.
Here is something to try for timing:
clock_t start = clock();
while(((float)clock()-(float)start)/CLOCKS_PER_SEC < .1)
{
//do nothing
}
This "does nothing" for a tenth of a second every "frame" although I believe while loops like that still use as much processor power as possible, but we don't care about that right?