{"id":106,"date":"2008-11-27T00:00:27","date_gmt":"2008-11-27T07:00:27","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=238"},"modified":"2008-11-27T00:00:27","modified_gmt":"2008-11-27T07:00:27","slug":"recursive-tree","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=106","title":{"rendered":"Recursive Tree"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar branches:int = 0;\r\nvar maxBranches:int = 400;\r\n \r\ngraphics.lineStyle(0,0x000000);\r\n\r\nmakeBranch(300,350,100,-45,45);\r\n\t \r\nfunction makeBranch(xp:Number, yp:Number, leng:Number, min:Number, max:Number):void {\r\n\r\n\tvar endX:Number, endY:Number;\r\n\tvar theta:Number = (min + Math.random()*(max-min) - 90) * Math.PI \/ 180;\r\n\t \r\n\tendX = xp + leng * Math.cos(theta);\r\n\tendY = yp + leng * Math.sin(theta);\r\n\r\n\tgraphics.moveTo(xp, yp);\r\n\tgraphics.lineTo(endX, endY);\r\n\t\r\n\tif (branches &lt; maxBranches) {\r\n\t\tvar newLength:Number = leng*.7; \r\n\t\tsetTimeout(makeBranch, 0, endX, endY, newLength, -90, 0);\r\n\t\tsetTimeout(makeBranch, 0, endX, endY, newLength, 0, 90);\r\n\t}\r\n\tbranches+=2;\r\n}\r\n<\/pre>\n<p>Draws a tree using recursion.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var branches:int = 0; var maxBranches:int = 400; graphics.lineStyle(0,0&#215;000000); makeBranch(300,350,100,-45,45); function makeBranch(xp:Number, yp:Number, leng:Number, min:Number, max:Number):void { var endX:Number, endY:Number; var theta:Number = (min + Math.random()*(max-min) &#8211; 90) * Math.PI \/ 180; endX = xp + leng * Math.cos(theta); endY = yp + leng * Math.sin(theta); graphics.moveTo(xp, yp); graphics.lineTo(endX, endY); if (branches &lt; maxBranches) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,33],"tags":[3,4,65,73],"class_list":["post-106","post","type-post","status-publish","format-standard","hentry","category-functions","category-graphics","tag-actionscript","tag-flash","tag-recursion","tag-tree"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=106"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/106\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}