Jonathan. Frech’s WebBlog

Prime Spiral (#33)

Jonathan Frech

Being fascinated by prime numbers I wanted to create a prime num­ber spiral gen­er­a­tor myself. It just goes through the numbers from 0 to and checks if they are prime. If they are prime, this rectangle in the spiral gets lit red, if it is not prime it gets lit dark gray. Because my algorithm for prime checking is very basic, I im­ple­ment­ed a per­for­mance helper. That way the spiral’s creation will slow down after time (due to the numbers that need to be checked getting bigger and bigger). The really interesting thing is, that — although they may seem ran­dom — prime numbers often form lines if shown in such a spiral. To see the comparison I included an image of a ran­dom­ly (50 % to 50 %) lit up board.

prime-spiral-8.png

Source code: prime-spiral.py