I've forgotten where I saw this---perhaps it was a Project Euler problem. In any case, you can see the pattern. It's a nice (fairly simple) exercise in Python to construct a list of lists and the functions to modify it. The great thing is that once you have the inner 3 x 3 circle correct, the rest is automatic. The code for this is in

`cycle.py`

.The real reason I'm posting about it is that it makes a fun plotting project for

`matplotlib`

, especially in combination with the prime number generator that we worked up the other day (in `primes.py`

).The graphic at the top of the post was obtained by modifying the array to hold n % 10 for each value, and using the matplotlib color map called "winter." I think for that one I had n = 50, so that's a 101 x 101 grid.

The prime example :) has n = 40 and uses the 'autumn' colormap. That's the one that

`script.py`

is set up to generate at the moment. Is there a pattern or is it just random?[UPDATE: I did a bit of testing. In tracing the results for the prime plot using a small n, I discovered that

`matplotlib`

has shown the matrix in a different way than I printed it at the top of the post. Their "heatmap" goes vertically for the first step and cycles clockwise; it is both a mirror image and rotated 180 degrees from the way I did it. Sorry. But, now that I'm done, I think I can just leave it that way... ]Zipped project files on Dropbox (here).