Posted by hexnet -

Having recently discovered that the prevailing number spirals of our age are not nearly hexagonal enough for my needs, I invented new a circular spiral based on centered hexagonal numbers, which I have named the GRAHAM SPIRAL. The first rotation contains 6 dots, representing the first 6 natural numbers, and each subsequent rotation n contains n*6 dots, in the fashion of hexagonal tessellation. In the examples above, variable dot sizes represent the number of unique prime factors in a given number, while the uniform dots represent primes themselves, but of course any arithmetic attributes can be plotted in the same fashion. The resulting patterns clearly demonstrate the deeply hexagonal structure of the natural numbers, &c.

(Style note: "GRAHAM SPIRAL," in sentence form, should always be written in ALL CAPS.)

I came upon for the idea for this spiral while investigating the Sacks spiral, which is based on one perfect square for each full rotation. That is, its rotations proceed 4, 9, 16... instead of 6, 12, 18... While certainly better (and indeed more hexagonal) than the square Ulam spiral, it still suffers from some obvious deficiencies. Circles don't pack around other circles in radiating squares, they pack in hexagons. Thus, a hexagonal spiral ought to be considered the "natural" way to plot a circular number spiral on the Euclidean plane. I mean, I'm not saying the Sacks spiral isn't interesting, or wouldn't be appropriate in another topological context, I'm just saying it doesn't exactly accentuate the organizational advantages of the Euclidean plane the way a hexagonal spiral does. I think there is a natural intuitiveness and ergonomicity to the GRAHAM SPIRAL that gives it distinct advantages over other, lesser spirals.

It doesn't particularly matter where you start, as it will eventually even out into roughly the same pattern, though you can twist it either way by adjusting the starting angle. In these examples, the 1-dot is plotted at approximately sixty degrees in the top right (positive) quadrant, spiraling counterclockwise, which puts 6, 60, and other highly composite numbers on the straight line going along the positive X axis from the origin. The 1, 7, 19... line (i.e., the proper centered hexagonal numbers) have more primes, so if you're into primes or something, it might make sense to center that line instead. This could also be accomplished by putting the 1 in the center, instead of the theoretical zero.

Anyway, The Python script—which I adapted from the Sacks spiral script at—is below, so the interested reader may recreate their own GRAHAM SPIRALS as they see fit. I edited this in a disjointed, nonlinear fashion over the course of several days, so it could probably stand to be cleaned up a bit. It requires the Elementary Number Theory (ent) package, which I can't find at the moment, but which I assure you is somewhere on these very internets at this time. Thank you.

# GRAHAM SPIRAL: The official script
from pyx import *
from ent import *
from math import *

ca = canvas.canvas()
tau = 2 * pi
off = 0
n = input("Rings:")
n = (n+1)*(n+1)*(n+1) - n*n*n - 1

# Use this to add an arbitary numerical offset
#off = input("Offset:")

# What "ring" any given natural number falls into
def hexring(n):
    val = 0
    while n > 0:
        val += 1
        n = n - 6 * val
    return val

# The nth hex number - 1, based on being the gnomon of the nth cube
def hexnum(n):
    return (n+1)*(n+1)*(n+1) - n*n*n - 1

for j in range(n):
    i = j + 1
    ring = hexring(i) # What ring is i in
    perim = ring * 6 # How many numbers are in the perimeter of that ring
    ringcount = hexnum(ring) - i # Where is i in that ring
    r = ring + 1 - (float(1) / float(perim)) * ringcount
    theta = (tau / perim) * ringcount
    x = cos(theta) * r
    y = -sin(theta) * r
    factors = factor(i+off)
    # Uncomment this to produce dotted primes
    #numfac = 0
    #for f in factors:
    #    numfac += f[1]
    #if numfac == 1: radius = 0.4
    #else: radius = 0.1
    # Set dot size by number of unique prime factors
    npf = len(factors)
    radius = pow(1.414, npf) / 12

    ca.fill(, y, radius))

d = document.document(pages = [, paperformat=document.paperformat.A4, fittosize=1)])
Submitted by anonymous - 2011-06-06 04:52

very gud

Submitted by cryptozoologist - 2011-08-19 14:19

from your code above:

# What "ring" any given natural number falls into
def hexring(n):
  val = 0
  while n > 0:
    val += 1
    n = n - 6 * val
  return val

perhaps you could use (i do not know python really, i'm guessing)

def hexring(n)
return floor(n^(1/3))

although the cube root might be at least as computationally cumbersome as the integer operations above, it would surely be faster beyond some n


Submitted by cryptozoologist - 2011-08-19 14:43

this might be of interest:

Submitted by Loren Pearson - 2013-04-26 23:14

Neat extension of an old idea. I first saw these in grade school as a thought problem for primes. The text had questions about predicting the patterns that arose out of successive spirals from three to ten. The hex based spiral was the objective at that point as all the primes are centered on multiples of six. I used this very concept to teach my own kids factoring. Good work on the plots - they and the Sack's / Ulam spirals all teach us stuff.

Submitted by anonymous ( - 2013-12-17 21:29

Hi Very interesting, thank you. I've been working on this kind of plot too. On my tumblr page I have posted lots of similar circular and polygonal plots and animations, including an animation showing a step-wise conversion of Ulam's spiral to the Sacks spiral. Cheers, DR

Submitted by chris_goldfrap - 2014-01-18 13:02

The four algebraic expressions governing straight line adjacent cell progressions from (or to) the centre 0 of a hexagonal number spiral are 3x^2, 3x^2 + x, 3x^2 + 2x, 3x^2 + 3x. The first, 3x^2, goes 0, 3, 12, 27, . . . The second, 3x^2 + x, goes through the centre where it is bent through 60 degrees to form apparently two spokes, respectively 0,2,10 . . . and 0,4,14. . .This shape also holds for 3x^2 + 2x, but bent the other way. 3x^2 + 3 is another unbent line (or maybe bent through 4x60 degrees) consisting solely of integer multiples of 6. For the straight line progressions on spirals with centre n, simply add + n to these expressions. Eg, for a centre 7, the second expression takes a classic quadratic form: 3x^2 + x + 7. These give us several rows of adjacent cells containing a number and that number's square. Eg 3x^2 + x + 9 gives us a line of cells containing both 19 and 361. Such square alignments in the spiral centre 7 amount to at least 14, for odd numbers 9 to 33, the most I've found so far for a spiral centering on a particular number. In an Ulam spiral, consisting of squares rather than hexagons, the quadratic expressions begin with 4x^2, not 3x^2. This must be because on a square grid, the cells are packed 8 round the central cell, but on a hex or chicken wire grid it's 6.