First 100,000 digits of pi and tau: Visual representation and code

There was an interesting post on Reddit for generating a visual representation of the first 100,000 digits of π\pi. I modified the code slightly use Brilliant's color palette, and made a variation for producing τ.\tau. I ran this code on Ubuntu Linux, but it should work on any Unix-based platform (Linux, OS X, BSD, etc), though you will have to figure out how to install dependencies yourself.

This works by generating 100,000 digits, converting them to color pixels in a 2-step process, and then generating a final image. Here's the result:

100,000 digits of pi 100,000 digits of pi

If you'd like to do it yourself, you will need basic command-line tools available on Unix, as well as:

  • the ImageMagick toolsuite for generating the final image
  • the pi utility for generating π\pi quickly; you could use arctan(1)×4\text{arctan}(1)\times4 as the original code does, but it is so slow that it never finished running on my machine and I gave up after ~30 mins.

    On Ubuntu, install dependencies like this:

apt-get install imagemagick pi

Here's the original code, modified to use Brilliant colors and for faster execution:

pi 100000 | \
  tr -cd '[[:digit:]]' | \
  tr '[0-9]' '[A-J]' | \
  sed -e 's/A/255 102 77 /g' \
      -e 's/B/252 160 74 /g' \
      -e 's/C/255 225 67 /g' \
      -e 's/D/103 217 76 /g' \
      -e 's/E/32 210 231 /g' \
      -e 's/F/39 210 231 /g' \
      -e 's/G/61 153 246 /g' \
      -e 's/H/12 106 199 /g' \
      -e 's/I/186 51 214 /g' \
      -e 's/J/249 112 191 /g' | \
  cat <(echo P3 400 250 255) - | \
  convert ppm:- -filter box -resize 800% pi-100k.png

Details on how it works:

  • Generate the digits of π\pi by using the pi utility
  • Trim off everything other than digits from the output
  • Convert the digits to letters
  • Replace the letters with RGB color codes that match the Brilliant palette
  • Add a header for the Netpbm graphics format that specifies the dimensions and color properties
  • And finally use the ImageMagick convert utility to produce a PNG image pi-100k.png

To produce τ\tau, modify the code slightly to multiply π\pi by 2 using the unix utility bc:

echo "scale=100000;$(pi 100000)*2" | bc | \
  convert ppm:- -filter box -resize 800% tau-100k.png

100,000 digits of tau 100,000 digits of tau

Pretty big difference between the two, no? =P

Can you figure out how to generate 1,000,000 digits of π\pi or τ\tau as a 1000x1000 pixel square image?

Note by Anton Kriksunov
4 years, 6 months ago

No vote yet
1 vote

  Easy Math Editor

This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.

When posting on Brilliant:

  • Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
  • Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
  • Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.
  • Stay on topic — we're all here to learn more about math and science, not to hear about your favorite get-rich-quick scheme or current world events.

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold

- bulleted
- list

  • bulleted
  • list

1. numbered
2. list

  1. numbered
  2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1

paragraph 2

paragraph 1

paragraph 2

[example link]( link
> This is a quote
This is a quote
    # I indented these lines
    # 4 spaces, and now they show
    # up as a code block.

    print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in \( ... \) or \[ ... \] to ensure proper formatting.
2 \times 3 2×3 2 \times 3
2^{34} 234 2^{34}
a_{i-1} ai1 a_{i-1}
\frac{2}{3} 23 \frac{2}{3}
\sqrt{2} 2 \sqrt{2}
\sum_{i=1}^3 i=13 \sum_{i=1}^3
\sin \theta sinθ \sin \theta
\boxed{123} 123 \boxed{123}


Sort by:

Top Newest

The 3rd digit of PI seems to be wrong in image. Could someone check?

Marcelo KortKamp - 4 years, 5 months ago

Log in to reply

Hi Anton,

I actually made a site a few months ago that builds the first 500,000 digits of pi pixel by pixel.

This picture might be based off of it.

Matt Formica - 4 years, 6 months ago

Log in to reply

how can I get long digits of pi in matlab?

Ibrahim Hameed - 4 years, 6 months ago

Log in to reply

I just found a way to get the value of pi:

Akshat Joshi - 4 years, 6 months ago

Log in to reply


Problem Loading...

Note Loading...

Set Loading...