Twin primes visualized over an Ulam Spiral in HTML5

Click here for the HTML5 demo in Javacript.

Two numbers p and q are twin primes if they are primes and |p| = 2.

The Ulam spiral, discovered by the mathematician Stanislaw Ulam in 1963, is a simple method to visualize prim numbers. Put the natural numbers in a spiral and draw only the ones which are primes.

In the visualization below, I’m drawing the prime numbers in two shades of green. Twin primes in light green and regular primes in dark green.

twin primes ulam spiral

The “vortex effect” is created because every twin prime is followed by its twin two steps before in the spiral. Below the same image with the zoom in the center:

twin primes ulam spiralIn the HTML5 demo in Javacript the spiral is draw dynamically in a image (warning: it can be a little bit computational intensive for your machine). You can play with the source-code on Github, and change the parameters. If you are looking for a plain ulam spiral, here it is one.

Update (May 30, 2013): This post was featured on the Blog of Math Blogs.

Update (November 25, 2013): I created a standalone Github project for this code.

https://github.com/silveira/ulam

3 thoughts on “Twin primes visualized over an Ulam Spiral in HTML5

  1. Can you post the code on GitHub? I have some configurable visualization modifications I can add to it if you do. More than happy to help you put it up, if needed.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>