Make RandomWalker Sand

random walk gif

Let's simulate a random walk with sand. A fun looking artsy one which moves where you can't predict.

Settings

Just create new sand by copying regular sand. Tweak the settings to be as shown here. We don't want gravity to affect RandomWalker, so change that to 0.0. We also don't want liquidity nor viscosity.

random walker settings

Rules

Open Rule Editor for RandomWalker.

Initialization

Let's first initialize a fixed speed towards a random direction for the material.

initialize random walk graph

We first check for a parameter extra_bit to see if our sand is initialized with velocity. If it has not been set yet, we then set the velocity to a random unit vector. We also then normalize the vector to keep the speed constant over time. Lastly, set the extra_bit to flag that the material has been initialized.

There are various ways you can initialize your material when it is drawn. Easiest way is to use the extra_bit parameter. But you can also use length of velocity or some other value that you know to be something at start, but change afterwards.

Random walk

Let's then rotate the direction over time to produce random walk.

random walker rotation

Before setting the velocity, rotate it with a random radian angle between -0.4 and 0.4. You should now see a random walk. To visualize this, select the Trace color mode.

random walk red

Color change

Last, let's change the color over time.

random walk color

To change color over time, let's first retrieve the current color value, then randomize that value by a small range (0.1) and set that to be the new color.

RandomWalker is now finished, and with Trace mode will produce beautiful visuals.

random walk color

Was this page helpful?