{"id":340,"date":"2011-12-01T01:00:07","date_gmt":"2011-12-01T09:00:07","guid":{"rendered":"http:\/\/new.joyofprocessing.com\/blog\/?p=340"},"modified":"2011-11-28T20:38:15","modified_gmt":"2011-11-29T04:38:15","slug":"romanesco","status":"publish","type":"post","link":"https:\/\/joyofprocessing.com\/blog\/2011\/12\/romanesco\/","title":{"rendered":"Romanesco"},"content":{"rendered":"<p><script type=\"application\/processing\">\/\/ Romanesco - Jim Bumgardner\n\/\/\n\/\/ A fractal that resembles Romanesco Broccoli\n\nint nbr_circles = 100;\n\nfloat phi = (sqrt(5)+1)\/2 - 1;            \/\/ golden ratio\nfloat golden_angle = phi * TWO_PI;        \/\/ golden angle\n\nvoid setup()\n{\n  size(500,500);\n  smooth();\n  background(64,0,64);\n  \n  fill(192,255,128);\n  noStroke();\n  noLoop();\n}\n\n\nvoid draw()\n{\n  drawFSpiral(width\/2, height\/2-8, width*.45, 3);\n}\n\n\nvoid drawFSpiral(float cx, float cy, float rad, int level)\n{\n  if (level == 0 || rad < 1) {\n    ellipse(cx, cy, rad*2, rad*2);\n  }\n  else {\n    float deviation = (nbr_circles-1)\/(float) (nbr_circles);\n    float lg_area = sq(rad) * PI;\n  \n    float mean_area = lg_area \/ nbr_circles;\n    \n    float min_area = mean_area * (1-deviation);\n    float max_area = mean_area * (1+deviation);\n    \n    float cum_area = 0;\n    \n    \n    for (int i = 1; i <= nbr_circles; ++i) {\n      float angle = i*golden_angle;\n    \n      float ratio = i \/ (float) nbr_circles;\n      float sm_area = map(ratio,0,1,min_area,max_area);\n      float sm_dia = 2 * sqrt( sm_area \/ PI );\n      float adj_sm_dia = sm_dia;\n    \n      cum_area += sm_area;\n    \n      float spiral_rad = sqrt( cum_area \/ PI );\n    \n      float x = cx + cos(angle) * spiral_rad;\n      float y = cy + sin(angle) * spiral_rad;\n      y += pow(2,level)*ratio;\n      drawFSpiral(x, y, adj_sm_dia\/2, level-1);\n    }\n  }\n}\n\n\n<\/script><\/p>\n<div class=\"ps_cap\"><a href=\"\/showexample.php?ex=romanesco\">source<\/a><\/div>\n<p>My daughter recently bought me a paperweight for my birthday made from a mold of a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Romanesco_broccoli\">romanesco broccoli<\/a>.  I made this sketch in tribute to that mathematically inspiring vegetable, shown here.<\/p>\n<p><img decoding=\"async\" src=\"\/img\/brassica_romanesco.jpg\" \/><\/p>\n<p>Most of the code comes from the Fibonacci Spiral I wrote about in <a href=\"\/blog\/2011\/10\/circles-spirals-and-sunflowers-part-2-2\/\">part 2 of my Circles, Spirals and Sunflowers<\/a> tutorial.<\/p>\n<p>In this version of the code, I made the spiral into a recursive function.  In the spot where I would normally draw a circle, I instead draw an equivalently sized spiral, by having the function call itself.  This continues ad-infinitum until the radius of the dots gets so small, that you can&#8217;t see the spiral, in which case I draw a tiny circle.<\/p>\n<p>I was able to get an ersatz 3D effect (without using actual 3d) by offsetting the y coordinate in octaves, based on the level of recursion.<\/p>\n<p>y += pow(2,level)*ratio;<\/p>\n<p>I imagine there is probably an elegant L-System that will draw the same pattern, but I haven&#8217;t worked it out yet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>source My daughter recently bought me a paperweight for my birthday made from a mold of a romanesco broccoli. I made this sketch in tribute to that mathematically inspiring vegetable, shown here. Most of the code comes from the Fibonacci Spiral I wrote about in part 2 of my Circles, Spirals and Sunflowers tutorial. In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9,19,8,17,18,10,15],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-circles","tag-fractal","tag-intermediate","tag-lsystem","tag-recursion","tag-spirals","tag-symmetry"],"_links":{"self":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":9,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":351,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions\/351"}],"wp:attachment":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}