WTF is this?

The images you see on this blog are output from various Ulam spiral generators I built in Flash, Python and most recently using Arduino. Generally, each dot in an image represents a number with integer 1 at center. In addition to writing algorithms to test each number for primality within a set I have discovered that an infinite number of calculations can be performed to create new designs and animation algorithms. The simplicity and speed of these algorithms make them an ideal fit for embedded systems graphics, scientific, mathematical and artistic explorations.

Wednesday, June 18, 2008

The Strangest, Most Beautiful Spiral



When my spiral generator output the above image for the first time, my jaw dropped. I had previously generated some interesting spiral images using triangular and square numbers, images that others have already generated elsewhere. But I have not yet seen anything as complex or intricate as this image, at least using the Ulam spiral algorithm.

The base calculation for generating this image (using ActionScript) follows:
(Math.round(Math.sqrt(Math.pow(n,2))*(1.6180339887*3.14159265)/2)%2==0)

It's the kind of pattern that would indeed make for an excellent Persian rug design, where your eye gets lost trying to follow the paths through the maze.

The following image uses the same calculation to determine the color of the dot, but rather than starting at the center here we are starting at top left 0,0 and moving across _x, then down and repeating until the space is filled.


Now we can see that the pattern is incredibly simple. If we say gray dots are 0 and red dots are 1, then we get:
0101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000010101010101010101010101000000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000000000000000000000000000101010101010101010101010000000000000000000000000000000000001010101010101010101010100000000000000

The groups of zeros alternate between 36 zeros and 38 zeros. In between these alternations is a string of zeros and ones. The first set of mixed digits is a 12-digit-long string "010101010101". After that it's always a 23-digit-long string "10101010101010101010101".

Now I'm trying to fine tune the algorithm to see if I can focus the pattern, perhaps improving it. Here is the result of using (Math.round(Math.sqrt(Math.pow(n, (Math.sqrt(2)+1) ))*2.2)%2==0)...As you can see there is not a huge difference.



Again...(Math.round(Math.sqrt(Math.pow(pInt, (Math.sqrt(2)+1) ))*2.3)%2==0). It seems the general characteristic of the pattern is similar, yet if you study it the differences become gradually more apparent. The way the spiral patterns are visually iterating reminds me a little bit of M.C. Escher's fish transforming into birds and back again. [See Metamorphosis]


After mucking about with the multiplier I have discovered that numbers greater than PI*PHI produce tinier spiral patterns to the point of turning the whole image into a seemingly random block of static. Going the other direction improves the clarity of the spiral patterns. Here is the same algorithm using 1.5 for our multiplier:


Multiplier = 1.2


Multiplier = .9


Multiplier = .2
We've crossed the threshold and the spirals are gone.


Multiplier = .005


Why do spirals form fancy daisy chains when using PI*PHI as the multiplier? Who knows? It's just how the dots line up.

I am curious as to why having PI as part of the algorithm leads to these spirals. Here is a linear matrix (L to R, T to B) using (Math.round( Math.pow(Math.sqrt(pInt)/Math.PI, 3.3) )%2==0) per dot.




Another kind of MaxiCode




Have you ever examined a package delivered by UPS and wondered what those curious looking labels containing a matrix of dots are used for? They are quite ingenious and beautiful in their own way. If you've gotten this far in this particular post you have probably noticed how you might generate your own "maxi-code" using the principles of a Ulam spiral, a left-to-right, top-to-bottom pattern, or any contained pattern. Encoding data into a pattern is a pretty simple affair. It's the encryption that is difficult. If we take the above example of converting the Ulam spiral to a series of ones and zeroes, you wind up with what could be interpreted as a set of data encoded as a binary set. But what algorithm should one use to convert these numbers back to human readable data? Or machine-readable data? Who knows! Such is the fun in creating your own patterns, meta-languages and encoding/decoding/codec algorithms.

1 comment:

Nikki said...

Beautiful work! I'd like to know how to generate spirals in JavaScript like you, because I have a project myself which is stuck because of this... Nonetheless, congratulations for this amazing piece of art!

Nicole