{"id":138,"date":"2010-12-28T15:13:00","date_gmt":"2010-12-28T15:13:00","guid":{"rendered":"http:\/\/witpoko.com\/?p=138"},"modified":"2010-12-28T15:13:00","modified_gmt":"2010-12-28T15:13:00","slug":"a-barnsleys-fern-in-7-lines-of-mathematica","status":"publish","type":"post","link":"https:\/\/witpoko.com\/?p=138","title":{"rendered":"A Barnsley&#8217;s Fern In 7 Lines of Mathematica"},"content":{"rendered":"<div style=\"text-align: left;\">I used to draw a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Barnsley's_fern\">Barnsley&#8217;s fern<\/a> with a program written in Pascal when I was 19 years old.  Yesterday someone asked about it in a forum I visited, so I drew another one using <i>Mathematica<\/i>.  The code is much shorter this time.  (I&#8217;m sure that many people can shorten it even more.)<\/div>\n<div><\/div>\n<div>Here&#8217;s the code to draw the fern with 10,000 points.  You can copy and paste and run it in <i>Mathematica<\/i>:<\/div>\n<p><\/p>\n<pre>          <p>ifsFern[p_] := Module[{i},<br \/>  i = Random[Integer, 99];<br \/>  If[i < 1, Return[{{0., 0.}, {0., .16}}.p ]];<br \/>  If[i >= 1 &amp;&amp; i < 86, Return[{{0.85, 0.04}, {-0.04, 0.85}}.p + {0., 1.6}]];<br \/>  If[i >= 86 &amp;&amp; i < 93, Return[{{0.20, -0.26}, {0.23, 0.22}}.p + {0., 1.6}]];<br \/>  If[i >= 93, Return[{{-0.15, 0.28}, {0.26, 0.24}}.p + {0., 0.44}]]] <\/p><p><br \/><\/p><p><\/p><p>Graphics[{RGBColor[0, 0.5, 0], Point[NestList[ifsFern, {0, 0}, 10000]]}]<\/p>   <p><\/p><pre><br \/><\/pre>\n<p><\/p>\n<div>The result looks like this:<\/div>\n<div style=\"font-family: Georgia, serif; \"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/1.bp.blogspot.com\/_5RhR8FFDW-4\/TRoAIA8YHeI\/AAAAAAAAFvs\/aSi52T9KkNk\/s400\/ifs_fern.png\" style=\"display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 198px; height: 400px;\" border=\"0\" alt=\"\" id=\"BLOGGER_PHOTO_ID_5555753228007120354\" \/><\/div>\n<div style=\"font-family: Georgia, serif; \"><\/div>\n<div style=\"font-family: Georgia, serif; \"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I used to draw a Barnsley&#8217;s fern with a program written in Pascal when I was &hellip; <a title=\"A Barnsley&#8217;s Fern In 7 Lines of Mathematica\" class=\"hm-read-more\" href=\"https:\/\/witpoko.com\/?p=138\"><span class=\"screen-reader-text\">A Barnsley&#8217;s Fern In 7 Lines of Mathematica<\/span>Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[31,108,29],"tags":[137],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-math","category-math-geek","category-mathematica","tag-graphics-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4UNq0-2e","_links":{"self":[{"href":"https:\/\/witpoko.com\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/witpoko.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/witpoko.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/witpoko.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/witpoko.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":0,"href":"https:\/\/witpoko.com\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"https:\/\/witpoko.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/witpoko.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/witpoko.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}