{"id":204,"date":"2018-05-04T09:50:59","date_gmt":"2018-05-04T09:50:59","guid":{"rendered":"http:\/\/cliffnordman.com\/blog\/?p=204"},"modified":"2019-02-26T11:28:26","modified_gmt":"2019-02-26T11:28:26","slug":"bodypaint-generator-code-clean-up","status":"publish","type":"post","link":"https:\/\/cliffnordman.com\/blog\/2018\/05\/04\/bodypaint-generator-code-clean-up\/","title":{"rendered":"Bodypaint Generator: Code Clean Up"},"content":{"rendered":"<p>My first draft of the bodypaint generator was a bit hacky, so I went back and cleaned it up a bit.<\/p>\n<p>I created &#8220;drawers&#8221; (things that draw, not parts of a dresser) that would draw different things: stars, letters, squares, etc.\u00a0 I could add more than one &#8220;drawer&#8221; to a placer and fill the canvas with, say, half circles and half heart emojis.\u00a0 But because I mis-used Javascript&#8217;s inheritance, I couldn&#8217;t create multiple copies of the same &#8220;drawer.&#8221; So half hearts and half smiley faces wouldn&#8217;t work, nor would half red stars with few points &amp; half green stars with many points.\u00a0 As the image below proves, I&#8217;ve removed that constraint. Now I can instantiate as many &#8220;drawers&#8221; as I like, of any type, and give them all different parameters.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-206\" src=\"http:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/multiple_drawers.png\" alt=\"\" width=\"600\" height=\"600\" srcset=\"https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/multiple_drawers.png 600w, https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/multiple_drawers-150x150.png 150w, https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/multiple_drawers-300x300.png 300w, https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/multiple_drawers-100x100.png 100w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>The placing feature was mixed in with the top-level generator object.\u00a0 I split it out to its own class, so I could make sub-classes and switch out or combine placers on one canvas just like I could use any combination of &#8220;drawers&#8221; with one placer.\u00a0 To demonstrate the new placer&#8217;s extensibility, I implemented a grid placer in addition to the random placer I made earlier.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-205\" src=\"http:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/grid.png\" alt=\"\" width=\"600\" height=\"600\" srcset=\"https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/grid.png 600w, https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/grid-150x150.png 150w, https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/grid-300x300.png 300w, https:\/\/cliffnordman.com\/blog\/wp-content\/uploads\/2018\/04\/grid-100x100.png 100w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Finally I made some quality-of-life improvements to make testing easier for myself.<\/p>\n<ol>\n<li>A &#8220;regenerate&#8221; button so I can re-run the generator without re-loading the page.<\/li>\n<li>A &#8220;save to PNG&#8221; button so I don&#8217;t have to Print-Screen, paste into an image editor, and crop each time I want to add an image to my blog. (If you look carefully at previous entries about this program, the images are off by a few pixels.)<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>My first draft of the bodypaint generator was a bit hacky, so I went back and cleaned it up a bit. I created &#8220;drawers&#8221; (things that draw, not parts of a dresser) that would draw different things: stars, letters, squares, etc.\u00a0 I could add more than one &#8220;drawer&#8221; to a placer and fill the canvas &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/cliffnordman.com\/blog\/2018\/05\/04\/bodypaint-generator-code-clean-up\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Bodypaint Generator: Code Clean Up&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/posts\/204"}],"collection":[{"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":1,"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":211,"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions\/211"}],"wp:attachment":[{"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cliffnordman.com\/blog\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}