Plotting Pi and Searching for Mona Lisa

This is a very nice video from Numberphile – where they use a string of numbers (pi) to write a quick Python Turtle code to create some nice graphical representations of pi.  I thought I’d quickly go through the steps required for people to do this by themselves.

Screen Shot 2022-02-04 at 12.14.47 PM

Firstly you can run the Turtle code on trinket.io.  If you type the above code this will take the decimal digits of pi one at a time and for each one move forward 10 steps and then turn by 36 degrees times by that digit.  So for example the 1 will lead to a right turn of 36 degrees and the 4 will lead to a right turn of 36 x 4 = 144 degrees.

Screen Shot 2022-02-04 at 12.20.25 PM

Next it would be nice to have more digits of pi to paste in rather than type.  So we can go to the onlinenumbertools website and generate as many digits of pi as we want.  Select them to be comma separated and also to not include the first digit 3.  You can then copy and paste this string in place of the 1,4,1 in the code above.

1000 digits of pi

Screen Shot 2022-02-04 at 12.08.50 PM

If we run this program after pasting the first 1000 digits of pi we get (after waiting a while!) the above picture. There are a number of questions that they then raise in the video – if this program was ran infinitely long would the whole screen eventually be black?  Would this create every possible image that can be created by 36 degree turns?  Would it be possible to send this picture (say to an alien civilization) and for the recipient to be able to reverse engineer the digits of pi?

2000 digits of pi

Screen Shot 2022-02-04 at 1.32.10 PM

If you increase the digits of pi to around 2000 you get the above picture.  The graph spends a large time in the central region before finally “escaping” to the left.  It then left my screen at the top.

3000 digits of pi

Screen Shot 2022-02-04 at 1.41.45 PM

We can see that the turtle “returned” from off the top of the screen and then joined back up with the central region.  This starts to look like a coastline – maybe the south of the UK!

Different bases: Base 3

Screen Shot 2022-02-04 at 12.32.36 PM

We can consider the digits of pi in base three – which means that they are all equivalent to 0,1,2.  This means that we can use these to specify either 0 degree, 120 degree or 240 degree turns.  We can change the code as shown above to achieve this.  Note the i%3 gives i mod 3.  For example if the digit is 8, then 8 mod 3 is 2 (the remainder when 8 is divided by 3) and so this would turn 120 x 2 = 240 degrees.

This then creates a pattern which looks similar to the Sierpinski triangle fractal design:

Screen Shot 2022-02-04 at 12.39.09 PM

Base 4

Using a similar method, we can create the following using a base 4 design:

Screen Shot 2022-02-04 at 12.49.03 PM

This creates what looks like a map layout.

Base 5:

Screen Shot 2022-02-04 at 1.13.58 PM

In base 5 the turtle quickly departed from my screen!  With turns of 72 we don’t see the tessellating shapes that we do with base 3 and 4.

Base 6:

Screen Shot 2022-02-04 at 1.26.12 PM

With a 60 degree turn we can now see a collection of equilateral triangles and hexagons.

You can explore with different numbers and different bases to see what patterns you can create!