## Sunday, December 11, 2011

### Interference Patterns

Edmund Harris recently posted some beautiful pictures created with modular arithmetic. I was surprised and intrigued to see this one, because it so closely resembled an image I made some years ago without thinking about modular arithmetic at all. I dug through my disorganized backups, and finally found it from circa 2004.

These images don't resize well. The scaling can both remove structure and produce artifacts that are not in the original, so here is an example detail portion of the full image.

These images are fractal looking, with repeating patterns at smaller scales. You can see the integers and fractions living in there. Perhaps cooler, the smaller repetitions seem to exist on a "higher level" than the basic repeating unit. They float along the patterns below, having a sort of ethereal existence.

If Edmund used modular arithmetic, how was my image made? Consider the function sin(x2). Here is a plot of it in the range of 0 to 15. You can see the frequency of the oscillations is increasing quickly with larger x.

Now consider sampling this function at discrete values of x in the larger range of 0 to 1000. When you get to higher values of x, this continuous function is oscillating back and forth a huge number of times between each successive value of x. Is there a pattern to be seen in the discretely sampled output values?

Finding a pattern on a 1D line is not so easy, but you can plot discrete values of sin(d2) on a 2D grid, where d is the distance of an image pixel to the origin. When the function value for each discrete pixel is calculated and plotted as a color, voila! The image appears, and the patterns undeniably jump out.

At the time, I attributed the effect to a Moire-like phenomenon, with an interference between the discrete grid of pixels and the continuous function. It was neat to read Edmund's explanation that modular arithmetic is behind the scenes. Maybe modular arithmetic is part of the magic behind Moire patterns?

I experimented with other functions as well, and here is a favorite. I love that it has both elliptical and hyperbolic patterns in it, and the transitioning between the two.