Skip to content
Posts May 17, 2018 1 min read

Ulam Spiral

An interactive p5.js implementation of the Ulam Spiral, featuring adjustable grid size, animation controls, and the ability to search for diagonal prime number patterns in the spiral.

Ulam Spiral

Launch this sketch is a new window (recommended)

Launch p5.js web editor

The Ulam Spiral or prime spiral is a graphical depiction of the set of prime numbers, devised by mathematician Stanislaw Ulam in 1963 and popularized in Martin Gardner’s Mathematical Games column in Scientific American a short time later. It is constructed by writing the positive integers in a square spiral and specially marking the prime numbers.

What I’ve done differently is allowed for iterating every integer in the grid forwards or backwards to search for long, connected diaganal lines of prime numbers in the grid. The framerate of the animation can be adjusted, as well as the “grid multiplier” which is how many cells to draw in each row and collumn. Double-clicking on the menu collapses it. There are also basic keyboard arrow controls:

Controls

- LEFT ARROW = Step backward - RIGHT ARROW = Step forwards - UP ARROW = Pause - DOWN ARROW = Pause

Connected Reading

Related entries

Chosen from shared tags, categories, and nearby section context.

Discovery Layer

Connected Memory

A focused relationship view around this entry, using shared categories and tags.

Categories 0
Tags 0
Posts 0