{"id":6734,"date":"2021-10-04T12:03:53","date_gmt":"2021-10-04T11:03:53","guid":{"rendered":"https:\/\/walkingrandomly.com\/?p=6734"},"modified":"2021-10-04T12:08:12","modified_gmt":"2021-10-04T11:08:12","slug":"matlab-mini-hack-no-matlab-license-required","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=6734","title":{"rendered":"MATLAB mini hack &#8211; No MATLAB license required"},"content":{"rendered":"<p>The MATLAB community site, <a href=\"https:\/\/uk.mathworks.com\/matlabcentral\/?s_tid=gn_mlc\">MATLAB Central<\/a>, is celebrating <a href=\"https:\/\/blogs.mathworks.com\/community\/2021\/09\/29\/twenty-a-birthday-a-contest-an-explosion-of-images\/\">its 20th anniversary<\/a> with a coding competition where the only aim is to make an interesting image with under 280 characters of code. The 280 character limit ensures that the resulting code is tweetable.\u00a0 There are a couple of things I really like about the format of this competition, other than the obvious fact that the only aim is to make something pretty!<\/p>\n<ol>\n<li>No MATLAB license is required! Sign up for a free MathWorks account and away you go.\u00a0 You can edit and run code in the browser.<\/li>\n<li><del>Stealing<\/del> reusing other people&#8217;s code is actively encouraged! The competition calls it remixing but GitHub users will recognize it as forking.\u00a0<\/li>\n<\/ol>\n<p>Here&#8217;s an example.\u00a0 <a href=\"https:\/\/uk.mathworks.com\/matlabcentral\/communitycontests\/contests\/4\/entries\/74\">I wrote a piece of code<\/a> to render the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Sierpi%C5%84ski_triangle\">Sierpi\u0144ski triangle &#8211; Wikipedia<\/a> using a simple random algorithm called the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chaos_game\">Chaos game.<\/a>\u00a0<\/p>\n<p><a href=\"https:\/\/uk.mathworks.com\/matlabcentral\/communitycontests\/contests\/4\/entries\/74\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-6737\" src=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/chaos3-1024x810.png\" alt=\"\" width=\"716\" height=\"567\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/chaos3-1024x810.png 1024w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/chaos3-300x237.png 300w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/chaos3-768x608.png 768w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/chaos3.png 1279w\" sizes=\"auto, (max-width: 716px) 100vw, 716px\" \/><\/a><\/p>\n<p>This is about as simple as the Chaos game gets and there are many things that could be done to produce a different image.\u00a0 As you can see from the <strong>Remix tree<\/strong> on the right hand side, I&#8217;ve already done one of them by changing a from 3 to 4 and adding some extra code to ensure that the same vertex doesn&#8217;t get chosen twice.\u00a0 \u00a0This is result:<\/p>\n<p><a href=\"https:\/\/uk.mathworks.com\/matlabcentral\/communitycontests\/contests\/4\/entries\/79\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-6739\" src=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/chaos4-1024x786.png\" alt=\"\" width=\"716\" height=\"480\" \/><\/a><\/p>\n<p>Someone else can now come along, hit the remix button and edit the code to produce something different again.\u00a0 \u00a0Some things you might want to try for the chaos game include<\/p>\n<ul>\n<li>Try changing the value of a which is used in the variables t and c to produce the vertices of a polygon on an enclosing circle.<\/li>\n<li>Instead of just using the vertices of a polygon, try using the midpoints or another scheme for producing the attractor points completely.<\/li>\n<li>Try changing the scaling factor &#8212; currently p=(p+s)\/2;<\/li>\n<li>Try putting limitations on which vertex is chosen. This remix ensures that the current vertex is different from the last one chosen.<\/li>\n<li>Each vertex is currently equally likely to be chosen using the code idx=randi(a); Think of ways to change the probabilities.<\/li>\n<li>Think of ways to colorize the plots.<\/li>\n<\/ul>\n<p>Maybe the chaos game isn&#8217;t your thing.\u00a0 You are free to create your own design from scratch or perhaps you&#8217;d prefer to remix some of the <a href=\"https:\/\/uk.mathworks.com\/matlabcentral\/communitycontests\/contests\/4\/entries\">other designs in the gallery.<\/a><\/p>\n<p>The competition is just a few hours old and there are already some very nice ideas coming out.<\/p>\n<p><a href=\"https:\/\/uk.mathworks.com\/matlabcentral\/communitycontests\/contests\/4\/entries\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-6740\" src=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/20gallery-1024x789.png\" alt=\"\" width=\"1024\" height=\"789\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/20gallery-1024x789.png 1024w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/20gallery-300x231.png 300w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/20gallery-768x592.png 768w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2021\/10\/20gallery.png 1230w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The MATLAB community site, MATLAB Central, is celebrating its 20th anniversary with a coding competition where the only aim is to make an interesting image with under 280 characters of code. The 280 character limit ensures that the resulting code is tweetable.\u00a0 There are a couple of things I really like about the format of [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[46,6,45,4,11,7],"tags":[],"class_list":["post-6734","post","type-post","status-publish","format-standard","hentry","category-fractals","category-general-math","category-just-for-fun","category-math-software","category-matlab","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-1KC","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/6734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6734"}],"version-history":[{"count":5,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/6734\/revisions"}],"predecessor-version":[{"id":6744,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/6734\/revisions\/6744"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}