{"id":958,"date":"2014-04-14T11:40:16","date_gmt":"2014-04-14T09:40:16","guid":{"rendered":"https:\/\/davidlebech.com\/thoughtflow\/?p=958"},"modified":"2014-04-16T18:10:30","modified_gmt":"2014-04-16T16:10:30","slug":"fractals-revisited","status":"publish","type":"post","link":"https:\/\/davidlebech.com\/thoughtflow\/fractals-revisited\/","title":{"rendered":"Fractals revisited"},"content":{"rendered":"<p><a href=\"https:\/\/davidlebech.com\/thoughtflow\/wp-content\/uploads\/fractal_2014.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/davidlebech.com\/thoughtflow\/wp-content\/uploads\/fractal_2014-150x136.png\" alt=\"Fractal\" width=\"150\" height=\"136\" class=\"alignright size-thumbnail wp-image-961\" srcset=\"https:\/\/davidlebech.com\/thoughtflow\/wp-content\/uploads\/fractal_2014-150x136.png 150w, https:\/\/davidlebech.com\/thoughtflow\/wp-content\/uploads\/fractal_2014-300x272.png 300w, https:\/\/davidlebech.com\/thoughtflow\/wp-content\/uploads\/fractal_2014.png 324w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a>Going through old code can be fun and educational. While updating my website, I took an extra look at some of my <a href=\"https:\/\/davidlebech.com\/code.html\" title=\"Code from David\" target=\"_blank\">featured code<\/a>. When I came across my simple <a href=\"http:\/\/davidlebech.com\/fractals\/\" title=\"Fractals by David\" target=\"_blank\">fractal simulations<\/a> on the <code>&lt;canvas&gt;<\/code> element, I was quite surprised to see how much I violated the Don&#8217;t Repeat Yourself (DRY) principle. The three simulations share more than 80% of the same code but they were each defined in separate files where all the code was repeated. The performance of the simulation had bothered me earlier, so I decided to take a look at the code and did the following:<\/p>\n<ul>\n<li>Consolidate the three simulation files into a single file.<\/li>\n<li>Optimize the animation loop.<\/li>\n<\/ul>\n<p>It was a fun little evening project to refactor some old code. There&#8217;s still some work that could be done, like removing the hardcoded dependency of the canvas element with a specific ID, but for a little showcase like this, I do not want to bother too much about that.<\/p>\n<p>By the way, <a href=\"https:\/\/github.com\/dlebech\/fractals-on-html-canvas\" title=\"Fractals on html canbas - Github\" target=\"_blank\">the code is online<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Going through old code can be fun and educational. While updating my website, I took an extra look at some of my featured code. When I came across my simple fractal simulations on the &lt;canvas&gt; element, I was quite surprised to see how much I violated the Don&#8217;t Repeat Yourself (DRY) principle. The three simulations [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[40,127,45],"class_list":["post-958","post","type-post","status-publish","format-standard","hentry","category-code","tag-canvas","tag-fractals","tag-programming"],"_links":{"self":[{"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/posts\/958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/comments?post=958"}],"version-history":[{"count":0,"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/posts\/958\/revisions"}],"wp:attachment":[{"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/media?parent=958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/categories?post=958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davidlebech.com\/thoughtflow\/wp-json\/wp\/v2\/tags?post=958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}