Try now in the
Open Cloud »
(no sign-in required)

# Pi Digit Necklaces

Make a necklace where the size of each bead is determined by a digit of π.

Run the code to get the first 100 digits of π in base 10. Try finding more than 100 digits:

This gives a list of the first 8 digits of π in base 10, followed by the number of digits to the left of the decimal point:

 In[1]:= XRealDigits[Pi, 10, 8]
 Out[1]=

Use First if you want just the list of digits:

 In[2]:= XFirst[RealDigits[Pi, 10, 8]]
 Out[2]=

 In[1]:= XFirst[RealDigits[Pi, 10, 100]]
 Out[1]=

Write out the digits with their size proportional to their values. Try scaling factors other than 10for example, 5:

Note: the scaling factor is the first occurrence of 10.

This writes the digit 5 in a 50-point font (a point is a printers measure equal to 1/72 inch):

 In[1]:= XStyle[5, 50]
 Out[1]=

This writes the digits from 1 to 5 in font sizes proportional to their values:

 In[2]:= X{Style[1, 10], Style[2, 20], Style[3, 30], Style[4, 40], Style[5, 50]}
 Out[2]=

A more efficient way to write the same thing uses a pure function. This is a pure function that adds 3 to a number:

 In[3]:= X(# + 3) &

Use it to add 3 to 5:

 In[4]:= X(# + 3) &[5]
 Out[4]=

Use the pure function to add 3 to every element of a list:

 In[5]:= X(# + 3) & /@ {1, 2, 3, 4, 5}
 Out[5]=

You can apply styles with pure functions. This makes the font size of each digit proportional to its value. Its the same result that you saw before:

 In[6]:= XStyle[#, 10 #] & /@ {1, 2, 3, 4, 5}
 Out[6]=

Use Row to turn the list into a row of digits without braces or commas:

 In[7]:= XRow[Style[#, 10 #] & /@ {1, 2, 3, 4, 5}]
 Out[7]=

Do the same thing with the first 100 digits of π :

 In[8]:= XRow[Style[#, 10 #] & /@ First[RealDigits[Pi, 10, 100]]]
 Out[8]=

 In[1]:= XRow[Style[#, 10 #] & /@ First[RealDigits[Pi, 10, 100]]]
 Out[1]=

Use disks instead of actual digits. Try other shapes, like (\[FilledSquare ]) or (\[FilledDiamond ]):

Type \[FilledCircle ] to get a disk character:

 In[1]:= X\[FilledCircle]

Make a large disk:

 In[2]:= XStyle[\[FilledCircle], 100]
 Out[2]=

Make disks whose sizes are proportional to the digits of π :

 In[3]:= XRow[Style[\[FilledCircle], 10 #] & /@ First[RealDigits[Pi, 10, 100]]]
 Out[3]=

 In[1]:= XRow[Style[\[FilledCircle], 10 #] & /@ First[RealDigits[Pi, 10, 100]]]
 Out[1]=

Pick a random color for each disk:

RandomColor gives a different color each time its run. Try running it several times:

 In[1]:= XRandomColor[]
 Out[1]=

Make a 100-point disk with a random color:

 In[2]:= XStyle[\[FilledCircle], 100, RandomColor[]]
 Out[2]=

Make randomly colored disks sized according to the digits of π :

 In[3]:= XRow[Style[\[FilledCircle], 10 #, RandomColor[]] & /@ First[RealDigits[Pi, 10, 100]]]
 Out[3]=

 In[1]:= XRow[Style[\[FilledCircle], 10 #, RandomColor[]] & /@ First[RealDigits[Pi, 10, 100]]]
 Out[1]=

Make a necklace of disks:

Put a Pane around each disk to make the disks line up. A Pane is an invisible container that takes on the height of the row and the width of its contents. The disks are centered vertically within the panes, which makes them align on their centers:

 In[1]:= XRow[Pane[Style[\[FilledCircle], 10 #, RandomColor[]]] & /@ First[RealDigits[Pi, 10, 10]]]
 Out[1]=

 In[1]:= XRow[Pane[Style[\[FilledCircle], 10 #, RandomColor[]]] & /@ First[RealDigits[Pi, 10, 100]]]
 Out[1]=

Share ItMake a digit necklace website:

Deploy a form makes a digit necklace with the starting digit and number of digits you specify:

 In[1]:= XCloudDeploy[ FormFunction[{{"n", "number of digits"} -> "Integer", {"start", "starting digit"} -> "Integer"}, Row[Pane[Style[\[FilledCircle], 10 #, RandomColor[]]] & /@ First[RealDigits[Pi, 10, #n, -#start]]] &, "PNG"], "Permissions" -> "Public" ]
 Out[1]=

Click the link in the output to visit the site.

Share the link by right-clicking it and choosing Copy Address. Paste the link into an email, tweet, or other message.

 In[1]:= XCloudDeploy[ FormFunction[{{"n", "number of digits"} -> "Integer", {"start", "starting digit"} -> "Integer"}, Row[Pane[Style[\[FilledCircle], 10 #, RandomColor[]]] & /@ First[RealDigits[Pi, 10, #n, -#start]]] &, "PNG"], "Permissions" -> "Public" ]
 Out[1]=