{"id":378,"date":"2011-12-06T23:56:49","date_gmt":"2011-12-07T07:56:49","guid":{"rendered":"http:\/\/new.joyofprocessing.com\/blog\/?p=378"},"modified":"2011-12-07T00:04:37","modified_gmt":"2011-12-07T08:04:37","slug":"xor-fractal","status":"publish","type":"post","link":"https:\/\/joyofprocessing.com\/blog\/2011\/12\/xor-fractal\/","title":{"rendered":"XOR Fractal"},"content":{"rendered":"<p><script type=\"application\/processing\">\/\/ XOR Fractal - Jim Bumgardner\n\nint fieldSize = 128;\nPGraphics fg;\n\nvoid setup()\n{\n  size(496,496);\n  fg = createGraphics(fieldSize,fieldSize,P2D);\n  fg.loadPixels();\n  frameRate(12);\n  smooth();\n}\n\nvoid draw()\n{\n  int n  = 0;\n  for (int y = 0; y < fieldSize; ++y) {\n    for (int x = 0; x < fieldSize; ++x) {\n      int v = ((y ^ (x+frameCount\/4)) % 3);\n      fg.pixels[n] = (v & 1) > 0? #FFFFFF : #000000;\n      n++;\n    }\n  }  \n  fg.updatePixels();\n  image(fg,0,0,496,496);\n}\n\n<\/script><\/p>\n<div class=\"ps_cap\"><a href=\"\/showexample.php?ex=xor_fractal\">source<\/a><\/div>\n<p>\nI stumbled across this interesting pattern many years ago while playing with the logic operators.  You take a grid of pixels, and you color each one based on the result of the following formula:<\/p>\n<p>(x XOR y) MODULO 3<\/p>\n<p>or<\/p>\n<p>(x ^ y) % 3<\/p>\n<p>x and y are the pixel&#8217;s coordinates.<\/p>\n<p>In this sketch I&#8217;m coloring the cells based on whether that value is even or odd.  I&#8217;ve tried numerous variations on this, including changing the constant from 3 to some other number (odd or prime numbers work best), and using various shading methods.  <\/p>\n<p>I call these &#8220;logic fractals&#8221; or &#8220;xor fractals&#8221; and this is one of my favorites.  I think it resembles a massive airfield or industrial park of the future.  Here I&#8217;ve zoomed in a bit, so you can see the detail.<\/p>\n<p>Many other strange and wonderful mathematical wallpapers still await your discovery.  You just need to combine x, y, and a motley assortment of logical and mathematical operators.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>source I stumbled across this interesting pattern many years ago while playing with the logic operators. You take a grid of pixels, and you color each one based on the result of the following formula: (x XOR y) MODULO 3 or (x ^ y) % 3 x and y are the pixel&#8217;s coordinates. In this [&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":[19,8,15,25,20],"class_list":["post-378","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-fractal","tag-intermediate","tag-symmetry","tag-tilings","tag-tiny-sketch"],"_links":{"self":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/378","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=378"}],"version-history":[{"count":7,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/378\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/posts\/378\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/media?parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/categories?post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/joyofprocessing.com\/blog\/wp-json\/wp\/v2\/tags?post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}