2017-03-29

Growing lichen

It was supposed to be a quick effect, and a trip to the past. It was one of the first things I ever coded in C, years ago. I found a description of it (was it a course?) in some old gaming magazine and decided to give it a try.

And now I've found the chapter about it in an old book I ordered for a couple of bucks from an American second-hand bookshop. The book is "The Magic Machine - A Handbook of Computer Sorcery" by A. K. Dewdney (see Fig. 1).

Fig. 1. "The Magic Machine" - can you feel the 90s?

Slo-Gro (slow growth) is a model of a particulate growth process, which happens for example during the aggregation of zinc particles in a two-dimensional film. The ions wander around until they meet the previously settled particles and thus form tree-like structures. DLA stands for diffusion-limited aggregation. The particles settle to form complex, fractal tree-like structures, which remind me of moss, or the Tree of Life - with branches that thrive and branches that wither out (see Fig. 2).

The analogy (well, one of the analogies) for the DLA process presented in the book is simply too precious to pass [1]:
The most colorful (albeit the least realistic) model for a DLA process involves a succesion of drunks wandering about in the dark until they stumble on a crowd of insensate comrades; lulled by the sounds of peaceful snoring, they instantly lie down to sleep. An aerial view of the slumbering crowd by morning light might well reveal the same fractal shape found in a zinc cluster or a soot patch.
On more serious note, the process can be described as follows. The particles (pixels, ions, ...) are initially placed randomly on the circumference of the circle. Each of the particles then wanders randomly (up, left, right, down) until it finds itself in the neighbourhood of some other particle, which is now stationary. The wandering particle then settles down and a now one is launched. The wandering process is stopped when the particles wanders out too far (outside the circle), or if it made too many steps (10 000) without any contact. New particle is generated to replace the strayed one. The process is repeated in a loop. At some point the arena will fill completely, and no new particles will find any more place to join.

In order to make the process quicker, you can influence the Brownian motion of the particles a little. I added a small displacement for the particles at each step, that slowly drags them towards the center, regardless of their random motion. This is controlled by the attraction parameter.


I made a small interactive simulator of the SLO-GRO effect: SLO-GRO Simulator
The code is available here: https://github.com/dagothar/slo-gro (beware: at some points it's one hack upon another!).

In the simulator you can launch your own slow growth process. You can draw on the board to create your own seeds, even during the simulation. You can tweak and mix the colors on the go. The process produces quite interesting graphical results (see figs. 3-9). Make sure to try different values of parameters, as well as different colors.

Fig. 3. The field overgrown.

Fig. 4. Dappled grass.

Fig. 5. Waves of grass.

Fig. 6. Creative palette.

Fig. 7. Delta step overgrown!

Fig. 8. Moon grass.

Fig. 9. Acid eye.


The moss grows quite quickly in the beginning, but it loses its pace abruptly: at some point the growing tree seems almost static. Even though the particles now have smaller distance to travel, more of them is necessary to fill the rings of increasing area (which grows as the square of the distance!). It will take several minutes to fill our Petri dish.

It is interesting to see what is the dimension of the structure generated by the slow growth process. For such a fractal, we can expect its fractal dimension to be somewhere between 1 and 2. Isn't it exciting that there are figures that dwell somewhere between being linear and planar? If you want to learn more about fractals and fractals dimension, I recommend watching an excellent video by 2Blue1Brown.

The fractal dimensions is basically the exponent by which the area of the object increases in response to scaling. For example, the "area" (length) of the line is linearly dependent on its scaling and thus the line is 1-dimensional. The area of a planar figure (e.g. a triangle) raises with the second power of the scaling, and thus the triangle is 2-dimensional. Similarly, a cube is 3-dimensional. The notion of dimension gets complicated with fractals. They tend to have fractional dimensions.

There's an easy way of calculating the fractal dimension of our structure. Simply measure the area (the number of settled points) for several different values of the radius. I did it by letting the moss grow, pausing at certain intervals, and measuring what the radius of the circle containing the sediment is. The data is presented in the plot below (fig. 10).
Fig. 10. Area of the structure vs. the total area.
The fractal dimension is calculated as the slope of the line of the structure area vs the scale plot.  My result is ~1.9. The fractal dimensions cited for Slo-Gro in [1] is 1.58. The discrepancy here is probably due to the attraction parameter; without it the tendrils of the tree tend to be considerably less dense (but then it takes massive amounts of time to generate the data! - see fig. 12). Feel free to experiment.

Fig. 11. Structure area (blue) and the total area (red) in log-log scale. The blue line has slightly smaller slope.
Fig. 12. Sparser structure with the attraction parameter set to 0.1 instead of 0.5.



Literature

[1] A. K. Dewdney, "The Magic Machine. A Handbook of Computer Sorcery", W. H. Freeman and Company, New York, 1990, ISBN: 0-7167-2149-2.

No comments:

Post a Comment