{"id":12791,"date":"2025-05-03T11:09:59","date_gmt":"2025-05-03T15:09:59","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=12791"},"modified":"2025-05-03T11:09:59","modified_gmt":"2025-05-03T15:09:59","slug":"l-systems-plants-fractal-curves-turtles-and-dragons","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2025\/05\/03\/l-systems-plants-fractal-curves-turtles-and-dragons\/","title":{"rendered":"L-systems, Plants, Fractal Curves, Turtles and Dragons"},"content":{"rendered":"<div class=\"content\"><!--introduction-->\n<p>No, this is not the script for an episode of \"Game of Thrones\". It is a blog post about Lindenmayer grammars, growing plants, space-filling fractals, turtle graphics and dragon curves.<\/p>\n<p>Here is the opening screen from our new program, MLogo.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/MLogo.png\" alt=\"\"> <\/p>\n<!--\/introduction-->\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li>\n<a href=\"#e4c73f18-5203-41ab-aae7-29dfc3c677bc\">L-systems<\/a>\n<\/li>\n<li>\n<a href=\"#2b729287-e100-42ba-9e7f-ceab5a7a41a4\">MLogo<\/a>\n<\/li>\n<li>\n<a href=\"#fb091433-870d-4ce0-82f6-4310e751f537\">Dragon Curve<\/a>\n<\/li>\n<li>\n<a href=\"#984588f4-4cb8-4fa5-8978-ec6e07b244b2\">Hilbert Curve<\/a>\n<\/li>\n<li>\n<a href=\"#27758267-deb0-4d68-9287-7f7af46ef0ec\">Gosper Fractal<\/a>\n<\/li>\n<li>\n<a href=\"#164f12f3-6e87-42af-b4e5-b38dd5d03010\">Algorithmic Beauty of Plants<\/a>\n<\/li>\n<li>\n<a href=\"#b0adc2d3-245d-4aca-b9f1-6a19fc7af2f3\">Software<\/a>\n<\/li>\n<\/ul>\n<\/div>\n<h4>L-systems<a name=\"e4c73f18-5203-41ab-aae7-29dfc3c677bc\"><\/a>\n<\/h4>\n<p>Aristid Lindenmayer (1925-1989) was a Hungarian biologist and botanist at the University of Utrecht. In 1968 he introduced a formal grammar for string rewrite rules that can describe living plants, artificial fractals, and especially, artificial fractals that model living plants.<\/p>\n<p>Lindenmayer's strings drive MLogo. A simple example is<\/p>\n<pre>  R = @(s) replace(s,\"A\",\"A+A-A\");<\/pre>\n<p>If you start with<\/p>\n<pre>  s = \"A\"<\/pre>\n<p>and repeat<\/p>\n<pre>  s = R(s)<\/pre>\n<p>three times, the result is<\/p>\n<pre>  A\n  A+A-A\n  A+A-A+A+A-A-A+A-A\n  A+A-A+A+A-A-A+A-A+A+A-A+A+A-A-A+A-A-A+A-A+A+A-A-A+A-A<\/pre>\n<h4>MLogo<a name=\"2b729287-e100-42ba-9e7f-ceab5a7a41a4\"><\/a>\n<\/h4>\n<p>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Logo_(programming_language)\" target=\"_blank\">Logo<\/a> is a programming language, aimed at young students, developed in 1967 by MIT professors Wally Feurzeig, Seymour Papert, and Cynthia Solomon. Logo has been very influential, spawning hundreds of implementations and successors. MLogo, short for MATLAB Logo, is another successor.<\/p>\n<p>A distinctive feature of Logo offprings is \"turtle graphics\". Basic Logo commands like <tt>step<\/tt>, <tt>turn<\/tt>, and <tt>draw<\/tt> drive a virtual tortoise, originally a motorized toy, and later a graphics cursor. Here is a sample with turtle driven by this Lindenmayer system.<\/p>\n<pre>A step forward\n+ turn left 90 degrees\n- turn right 90 degrees<\/pre>\n<pre>s = A+A-A-A+<\/pre>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/Turtle-2.gif\" alt=\"\"> <\/p>\n<h4>Dragon Curve<a name=\"fb091433-870d-4ce0-82f6-4310e751f537\"><\/a>\n<\/h4>\n<p>The dragon space-filling fractal curve was invented by NASA physicist John Heighway and his colleagues and featured in Martin Gardner's <i>Scientific American<\/i> column in 1967. I made a <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2018\/04\/06\/the-dragon-curve\">Cleve's Corner<\/a> posting about the dragon curve in 2018.<\/p>\n<p>Here is MLogo's dragon.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/Dragon-1.gif\" alt=\"\"> <\/p>\n<p>Here is a frame from \"Numberphile\" video where Brady Haran visits <a href=\"https:\/\/www.youtube.com\/watch?v=v678Em6qyzk\" target=\"_blank\">Don Knuth<\/a> and the unique ceramic tile dragon in his home.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/Knuth.png\" alt=\"\"> <\/p>\n<h4>Hilbert Curve<a name=\"984588f4-4cb8-4fa5-8978-ec6e07b244b2\"><\/a>\n<\/h4>\n<p>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/David_Hilbert\" target=\"_blank\">David Hilbert<\/a> (1862-1943), one of the most influential mathematicians of his era, introduced the space-filling fractal <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hilbert_curve\" target=\"_blank\">Hilbert curve<\/a> in 1891.<\/p>\n<p>Here is MLogo's Hilbert curve.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/Hilbert.gif\" alt=\"\"> <\/p>\n<p>Here is a crazy application of the Hilbert curve, Randall Munroe's view of Internet addresses in 2006, <a href=\"https:\/\/xkcd.com\/195\" target=\"_blank\">https:\/\/xkcd.com\/195<\/a>.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/xkcd.png\" alt=\"\"> <\/p>\n<p>\n<a href=\"https:\/\/xkcd.com\/195\" target=\"_blank\">https:\/\/xkcd.com\/195<\/a>\n<\/p>\n<h4>Gosper Fractal<a name=\"27758267-deb0-4d68-9287-7f7af46ef0ec\"><\/a>\n<\/h4>\n<p>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Bill_Gosper\" target=\"_blank\">Bill Gosper<\/a>, one of the original MIT \"hackers\", has made major contributions to Lisp and Macsyma, found the \"glider gun\" for Conway's Game of Life, and invented the Gosper fractal.<\/p>\n<p>Here is MLogo's rendition.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/Gosper-1.gif\" alt=\"\"> <\/p>\n<p>Dragon Nerd creates jewelry from the Gosper curve and other fractals.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/DragonNerd.png\" alt=\"\"> <\/p>\n<p>\n<a href=\"https:\/\/www.etsy.com\/shop\/DragonNerd\" target=\"_blank\">https:\/\/www.etsy.com\/shop\/DragonNerd<\/a>\n<\/p>\n<h4>Algorithmic Beauty of Plants<a name=\"164f12f3-6e87-42af-b4e5-b38dd5d03010\"><\/a>\n<\/h4>\n<p>\"The Algorithmic Beauty of Plants\" is a beautiful book by Przemyslaw Prusinkiewicz and Aristid Lindenmayer, featuring over fifty color figures of computer-generated plants. The original book is available from <a href=\"https:\/\/link.springer.com\/book\/10.1007\/978-1-4613-8476-2\" target=\"_blank\">Springer Nature<\/a>. A PDF version is available from <a href=\"https:\/\/algorithmicbotany.org\/papers\/#abop\" target=\"_blank\">AlgormicBotany<\/a> at the University of Calgary.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/abop.png\" alt=\"\"> <\/p>\n<p>This is MLogo's rendition of one small example.<\/p>\n<p>\n<img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/Plant-2.gif\" alt=\"\"> <\/p>\n<h4>Software<a name=\"b0adc2d3-245d-4aca-b9f1-6a19fc7af2f3\"><\/a>\n<\/h4>\n<p>\n<a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/MLogo.m\">https:\/\/blogs.mathworks.com\/cleve\/files\/MLogo.m<\/a>\n<\/p>\n<script language=\"JavaScript\"> <!-- \n    function grabCode_038066df016b4e6685a8571703c3f9db() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='038066df016b4e6685a8571703c3f9db ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 038066df016b4e6685a8571703c3f9db';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        copyright = 'Copyright 2025 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('<pre>\\n');\n        d.write(code_string);\n\n        \/\/ Add copyright line at the bottom if specified.\n        if (copyright.length > 0) {\n            d.writeln('');\n            d.writeln('%%');\n            if (copyright.length > 0) {\n                d.writeln('% _' + copyright + '_');\n            }\n        }\n\n        d.write('<\/pre>\\n');\n\n        d.title = title + ' (MATLAB code)';\n        d.close();\n    }   \n     --> <\/script>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\">\n<br>\n<a href=\"javascript:grabCode_038066df016b4e6685a8571703c3f9db()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \n      the MATLAB code <noscript>(requires JavaScript)<\/noscript>\n<\/span><\/a>\n<br>\n<br>\n      Published with MATLAB&reg; R2024b<br>\n<\/p>\n<\/div>\n<!--\n038066df016b4e6685a8571703c3f9db ##### SOURCE BEGIN #####\n%% L-systems, Plants, Fractal Curves, Turtles and Dragons\n% No, this is not the script for an episode of \"Game of Thrones\".\n% It is a blog post about\n% Lindenmayer grammars, growing plants, space-filling fractals,\n% turtle graphics and dragon curves.\n%\n% Here is the opening screen from our new program, MLogo.\n%\n% <<MLogo.png>>\n%\n\n%% L-systems\n% Aristid Lindenmayer (1925-1989) was a Hungarian biologist and\n% botanist at the University of Utrecht.  In 1968 he introduced a\n% formal grammar for string rewrite rules that can describe  \n% living plants, artificial fractals, and especially, artificial\n% fractals that model living plants. \n%\n% Lindenmayer's strings drive MLogo.  A simple example is\n%\n%    R = @(s) replace(s,\"A\",\"A+A-A\");\n%\n% If you start with\n%\n%    s = \"A\"\n%\n% and repeat\n%\n%    s = R(s)\n%\n% three times, the result is\n%\n%    A\n%    A+A-A\n%    A+A-A+A+A-A-A+A-A\n%    A+A-A+A+A-A-A+A-A+A+A-A+A+A-A-A+A-A-A+A-A+A+A-A-A+A-A\n%\n\n%% MLogo\n% <https:\/\/en.wikipedia.org\/wiki\/Logo_(programming_language)\n% Logo> is a programming language, aimed at young students,\n% developed in 1967 by MIT professors Wally Feurzeig, Seymour Papert,\n% and Cynthia Solomon.  Logo has been very influential, spawning\n% hundreds of implementations and successors.  MLogo, short for\n% MATLAB Logo, is another successor.\n%\n% A distinctive feature of Logo offprings is \"turtle graphics\".\n% Basic Logo commands like |step|, |turn|, and |draw| drive a\n% virtual tortoise, originally a motorized toy, and later a graphics \n% cursor.  Here is a sample with turtle driven by this\n% Lindenmayer system. \n%\n%  A step forward\n%  + turn left 90 degrees\n%  - turn right 90 degrees\n%\n%  s = A+A-A-A+ \n%\n% <<Turtle-2.gif>>\n%\n\n%% Dragon Curve\n% The dragon space-filling fractal curve was invented by NASA\n% physicist John Heighway and his colleagues and featured in \n% Martin Gardner's _Scientific American_ column in 1967. I made a\n% <https:\/\/blogs.mathworks.com\/cleve\/2018\/04\/06\/the-dragon-curve\n% Cleve's Corner> posting about the dragon curve in 2018.\n%\n% Here is MLogo's dragon.\n%\n% <<Dragon-1.gif>>\n%\n% Here is a frame from \"Numberphile\" video where Brady Haran visits\n% <https:\/\/www.youtube.com\/watch?v=v678Em6qyzk Don Knuth>\n% and the unique ceramic tile dragon in his home.\n%\n% <<Knuth.png>>\n\n%% Hilbert Curve\n% <https:\/\/en.wikipedia.org\/wiki\/David_Hilbert David Hilbert>\n% (1862-1943), one of the most influential mathematicians\n% of his era, introduced the space-filling fractal \n% <https:\/\/en.wikipedia.org\/wiki\/Hilbert_curve Hilbert curve>\n% in 1891.\n%\n% Here is MLogo's Hilbert curve.\n%\n% <<Hilbert.gif>>\n%\n% Here is a crazy application of the Hilbert curve,\n% Randall Munroe's view of Internet addresses in 2006,\n% <https:\/\/xkcd.com\/195>.\n%\n% <<xkcd.png>>\n%\n% <https:\/\/xkcd.com\/195>\n%\n%% Gosper Fractal\n% <https:\/\/en.wikipedia.org\/wiki\/Bill_Gosper Bill Gosper>,\n% one of the original MIT \"hackers\",\n% has made major contributions to Lisp and Macsyma,\n% found the \"glider gun\" for Conway's Game of Life,\n% and invented the Gosper fractal.\n%\n% Here is MLogo's rendition.\n%\n% <<Gosper-1.gif>>\n%\n% Dragon Nerd creates jewelry from the Gosper curve and other fractals.\n%\n% <<DragonNerd.png>>\n%\n% <https:\/\/www.etsy.com\/shop\/DragonNerd>\n\n%% Algorithmic Beauty of Plants\n% \"The Algorithmic Beauty of Plants\" is a beautiful book by\n% Przemyslaw Prusinkiewicz and Aristid Lindenmayer, featuring\n% over fifty color figures of computer-generated plants.\n% The original book is available from \n% <https:\/\/link.springer.com\/book\/10.1007\/978-1-4613-8476-2\n% Springer Nature>.  A PDF version is available from\n% <https:\/\/algorithmicbotany.org\/papers\/#abop\n% AlgormicBotany> at the University of Calgary.\n%\n% <<abop.png>>\n%\n% This is MLogo's rendition of one small example.\n%\n% <<Plant-2.gif>>\n%\n\n%% Software\n%\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/MLogo.m>\n\n##### SOURCE END ##### 038066df016b4e6685a8571703c3f9db\n-->\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/Turtle-2.gif\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction-->\n<p>No, this is not the script for an episode of \"Game of Thrones\". It is a blog post about Lindenmayer grammars, growing plants, space-filling fractals, turtle graphics and dragon curves.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2025\/05\/03\/l-systems-plants-fractal-curves-turtles-and-dragons\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":12812,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,32,18,5,23,8],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/12791"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=12791"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/12791\/revisions"}],"predecessor-version":[{"id":12815,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/12791\/revisions\/12815"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/12812"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=12791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=12791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=12791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}