Tag Archives: fractal

XOR Fractal

6 Dec

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’s coordinates.

In this sketch I’m coloring the cells based on whether that value is even or odd. I’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.

I call these “logic fractals” or “xor fractals” and this is one of my favorites. I think it resembles a massive airfield or industrial park of the future. Here I’ve zoomed in a bit, so you can see the detail.

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.