Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »
Try it now »
(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:

SHOW/HIDE DETAILS

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:

RealDigits[Pi, 10, 8]

Use First if you want just the list of digits:

First[RealDigits[Pi, 10, 8]]

HIDE DETAILS
First[RealDigits[Pi, 10, 100]]

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

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

SHOW/HIDE DETAILS

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

Style[5, 50]

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

{Style[1, 10], Style[2, 20], Style[3, 30], Style[4, 40], Style[5, 50]}

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

(# + 3) &

Use it to add 3 to 5:

(# + 3) &[5]

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

(# + 3) & /@ {1, 2, 3, 4, 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:

Style[#, 10 #] & /@ {1, 2, 3, 4, 5}

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

Row[Style[#, 10 #] & /@ {1, 2, 3, 4, 5}]

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

Row[Style[#, 10 #] & /@ First[RealDigits[Pi, 10, 100]]]

HIDE DETAILS
Row[Style[#, 10 #] & /@ First[RealDigits[Pi, 10, 100]]]

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

SHOW/HIDE DETAILS

Type \[FilledCircle ] to get a disk character:

\[FilledCircle]

Make a large disk:

Style[\[FilledCircle], 100]

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

Row[Style[\[FilledCircle], 10 #] & /@ First[RealDigits[Pi, 10, 100]]]

HIDE DETAILS
Row[Style[\[FilledCircle], 10 #] & /@ First[RealDigits[Pi, 10, 100]]]

Pick a random color for each disk:

SHOW/HIDE DETAILS

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

RandomColor[]

Make a 100-point disk with a random color:

Style[\[FilledCircle], 100, RandomColor[]]

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

Row[Style[\[FilledCircle], 10 #, RandomColor[]] & /@ First[RealDigits[Pi, 10, 100]]]

HIDE DETAILS
Row[Style[\[FilledCircle], 10 #, RandomColor[]] & /@ First[RealDigits[Pi, 10, 100]]]

Make a necklace of disks:

SHOW/HIDE DETAILS

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:

Row[Pane[Style[\[FilledCircle], 10 #, RandomColor[]]] & /@ First[RealDigits[Pi, 10, 10]]]

HIDE DETAILS
Row[Pane[Style[\[FilledCircle], 10 #, RandomColor[]]] & /@ First[RealDigits[Pi, 10, 100]]]

Share Itmake a digit necklace website:

SHOW/HIDE DETAILS

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

CloudDeploy[ 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" ]

Click the link in the output to visit the site.

Tell the world about your creation by sharing the link via email, tweet or other message.

HIDE DETAILS
CloudDeploy[ 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" ]