Turn your Computer into a Gardener to grow Flowers and Trees with a Turtle and L-Systems (Part 2)

in #science7 years ago

In this post I'll go on explaining how your computer can grow nicely looking trees and plants. You can find the first part introducing the little turtle who does all the gardening in PART 1.

turtle

As a reminder, we established L-Systems as so called generative grammars. These are rewriting rules like: F -> F+F-. We can apply these rules iteratively as often as we please. The resulting string like F+F-F+F- can be read by a little obedient turtle with a pencil. The turtle moves either Forward or turns left (+) or right (-) accordingly. Thereby, it draws nice structures such as the Kochcurve:

Kochcurve

Our Turtle needs a Memory

Still, this does not really look like a plant, yet. Our rule system needs one further adjustment. Let us now introduce the [ and ] opening and closing bracket operators. Thereby we add a particular type of memory, also called stack in computer science, to our turtle. This means whenever the turtle reads a [ it should remember its current position and orientation and keep it in mind. If it stumbles upon a ] it should recall its former state from its memory and return to the remembered position and orientation without drawing stuff on its way back. In other words, a ] teleports the turtle back to where it was when the last [ appeared before. With this simple addition our turtle is able to draw realistic looking plants. See below for a whole set of different grammars and corresponding plants:

Stack Plants
In this figure n is the number of iterations, sigma denotes the fixed turning angle, the character X is only needed for the grammar. It is ignored by the drawing turtle. Image taken from [1]

Note that the X symbol is needed here for some plants. Since our turtle has no clue
what X means, it will simply ignore it. It is only used to generate the strings and is irrelevant for the drawing. Furthermore, I wrote a little Python script that you can use to draw these plants by yourself, the code is published in my github repository.

More advanced L-Systems

Of course, our simple turtle drawings are not the end of L-Systems. We could modfiy the drawing process and allow for three-dimensional rotations, add color, and allow additions of entire leaves:

3d-plant
Image taken from [1]

And this really does look like a realistic plant.

We can further augment our L-System by introducing randomness. We can allow for alternative rules for the same initial character. The selection of rules is random following a certain probability:

A -> AB : 20%

A -> BA : 80%

Here A will be replaced by AB with 20% chance and by BA in the remaining 80% of cases. With these kind of stochastic rules we can introduce variations in our plants:

stochastic
Stochastic plants taken from [1]

Although these individual plants are different, you might think they belong to the same species.

As a next augmentation to our system we can introduce context sensitivity:

B<A>C -> ACA

In this rule A will only be replaced by ACA if a B can be found to the left and a C to the right of A. Context sensitive plants look like this, for example:

context
Context sensitive plants from [1]

Context sensitive grammars can not only be used for drawing, but also simulate nutrient flow within plants or the diffusion of other chemicals.

Finally, we can complicate our system further by introducing parametrized L-Systems. We can add logical and mathematical operators, for instance:

A(t): t > 3 -> B(4t) C(t^2+sin(t),ln(t))

A will be replaced by BC if t is larger than 3. Moreover, t is passed onto B and C via some complex functions. With these kinds of mathemtical parametrizations, one can add a model of the plant's environment such as soil nutrients or light sources.

For instance, we could simulate plant growth within a restricted box:

boxplant
Image taken from [2]

Or the development of trees that compete for sunlight and, therefore, grow in opposite directions:

competing
Image taken from [3]

L-Systems are powerful tools to model realistic plants. They are heavily used in science, for example, to investigate tree metabolism [4] or root growth [5]. L-Systems are not restricted to plants, they can also be used for other natural phenomena such as the growth of nerve tissue [6] or to generate realistic scenarios in computer games [7].

Finally, as a reminder, if you want to play around with L-Systems yourself, I provided a little Python script to do so on my Github profile.


import turtle as t

def init_turtle():
    ...

References

[1] P. Prusinkiewicz and A. Lindenmayer, The Algorithmic Beauty of Plants. Springer, 1990.

[2] P. Prusinkiewicz, M. James and R. Mech, Synthetic Topiary, Computer Graphics Proceedings, 1994.

[3] R. Mech and P. Prusinkiewicz, “Visual models of plants interacting with their environment,” in Proceedings of the 23rd annual conference on Computer graphics and interactive techniques, ser. SIGGRAPH ’96. New York, NY, USA: ACM, 1996, pp. 397–410.

[4] M. T. Allen, P. Prusinkiewicz, and T. M. DeJong, “Using l-systems for modeling source-sink interactions, architecture and physiology of growing trees: The l-peach model,” New Phytologist, vol. 166, no. 3, pp. pp. 869–880, 2005.

[5] D. Leitner, S. Klepsch, G. Bodner, and A. Schnepf, “A dynamic root system growth model based on l-systems,” Plant and Soil, vol. 332, pp. 177–192, 2010, 10.1007/s11104-010-0284-7.

[6] H. Jelinek, A. Karperien, D. Cornforth, R. M. C. Junior, J. de Jesus Gomes, R. Marcondes, C. Junior, J. Jesus, and G. Le, “Micromod - an l-systems approach to neuron modelling,” in National University, 2002, pp. 156–163.

[7] StackOverflow: L-Systems to grow city models

Sort:  

You got a 0.51% upvote from @upme requested by: @smcaterpillar.
Send at least 2.5 SBD to @upme with a post link in the memo field to receive upvote next round.
To support our activity, please vote for my master @suggeelson, as a STEEM Witness

Enjoy the vote and reward!

it's like the hello world of geometry programming.
i made these 4 and 5 sided snowflakes , last christmas.
i didn't feel like going with the regular 6-sided ones.

This post has received a 0.79 % upvote from @booster thanks to: @smcaterpillar.

Remember that children, marriages, and flower gardens reflect the kind of care they get.

Education is not preparation for life; education is life itself.

The number one benefit of information technology is that it empowers people to do what they want to do. It lets people be creative. It lets people be productive. It lets people learn things they didn't think they could learn before, and so in a sense it is all about potential.

Information technology and business are becoming inextricably interwoven. I don't think anybody can talk meaningfully about one without the talking about the other.

!originalworks

The @OriginalWorks bot has determined this post by @smcaterpillar to be original material and upvoted it!

ezgif.com-resize.gif

To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!

Please note that this is a BETA version. Feel free to leave a reply if you feel this is an error to help improve accuracy.

Education is not preparation for life; education is life itself.

The human soul is hungry for beauty; we seek it everywhere - in landscape, music, art, clothes, furniture, gardening, companionship, love, religion, and in ourselves. No one would desire not to be beautiful. When we experience the beautiful, there is a sense of homecoming.

Coin Marketplace

STEEM 0.20
TRX 0.14
JST 0.030
BTC 64294.06
ETH 3427.66
USDT 1.00
SBD 2.59