{"id":263,"date":"2010-01-13T22:02:23","date_gmt":"2010-01-14T04:02:23","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/?p=263"},"modified":"2010-01-13T22:02:23","modified_gmt":"2010-01-14T04:02:23","slug":"xkcd-self-description-solved-with-pythonpygame","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2010\/01\/13\/xkcd-self-description-solved-with-pythonpygame\/","title":{"rendered":"xkcd &#8220;Self-Description&#8221; solved with python+pygame"},"content":{"rendered":"<p>Well, something about this xkcd comic drew me in &#8230;<\/p>\n<p><a href=\"http:\/\/xkcd.com\/688\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/imgs.xkcd.com\/comics\/self_description.png\" alt=\"\" width=\"740\" height=\"180\" \/><\/a><\/p>\n<p>The 3rd panel reminded me of a study I did in college on <a href=\"http:\/\/en.wikipedia.org\/wiki\/Iterated_function_system\">iterated function system fractals<\/a>. \u00a0These fractals are known for creating ferns, trees, and the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Sierpinski_gasket\">Sierpinski triangle<\/a>. \u00a0There are a number of ways of creating these fractals, but one of them is called (something like) the reducing photo copier method. \u00a0Where you can start with ANY starting image on your photo copier, and just shrink the images, make a few copies, position them on the copier, and repeat. \u00a0Eventually your image converges towards the fern \/ triangle \/ whatever if you are precise. \u00a0(This can be done with a &#8216;Real Life&#8217; photo copier for simple IFS like the Sierpinski triangle.)<\/p>\n<p>So as a way to avoid work that I&#8217;m supposed to be doing this evening, I figured I&#8217;d see how &#8220;accurate&#8221; this comic was. \u00a0Here&#8217;s my <a href=\"https:\/\/www.philhassey.com\/blog\/wp-content\/uploads\/2010\/01\/xkcd688.zip\">pygame code<\/a> that checks it out. \u00a0If you run main.py it will start with an image (the xkcd logo) and each time you press a key it will do an iteration of re-creating the comic. \u00a0You can see it flashing between the current iteration and the original strip. \u00a0After about 4-5 iterations the images converge (pretty closely.)<\/p>\n<p>The most interesting bit was trying different starting images and seeing how long it took to converge. \u00a0Starting with all black \u00a0it takes 6 iterations. \u00a0Starting with all white takes 5 iterations. \u00a0And starting with the xkcd logo takes 4 iterations. \u00a0The logo probably goes the quickest because it has some black and white in it (like this image) so it converges faster. \u00a0(You can edit main.py towards the bottom page to try these different starting points.)<\/p>\n<p>So .. there ya go! \u00a0Enjoy!<\/p>\n<p>-Phil<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, something about this xkcd comic drew me in &#8230; The 3rd panel reminded me of a study I did in college on iterated function system fractals. \u00a0These fractals are known for creating ferns, trees, and the Sierpinski triangle. \u00a0There are a number of ways of creating these fractals, but one of them is called [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,3,2],"tags":[],"class_list":["post-263","post","type-post","status-publish","format-standard","hentry","category-crazy","category-pygame","category-python"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":1,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/263\/revisions\/265"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}