Download or view piPoster.frink in plain text format
/** This is a program to print a poster of the digits of pi. It uses a
system-of-equations solver to do the algebra to fit as closely to the
dimensions of a page as possible. */
use systemSolver2.frink
use pi2.frink
symbolicMode[true]
layout = new System[[pageWidth pageHeight === charHeight charWidth numChars,
charWidth === 6/10 charHeight,
lines === pageHeight / charHeight,
charsPerLine === numChars / lines],
[]]
digits = 10000
pageWidth = 8 in
pageHeight = 10.5 in
// Read number of digits from command-line argument if there is one.
if length[ARGS] > 0
digits = eval[ARGS@0]
// Read width and height from command-line arguments if they exist.
if length[ARGS] >= 3
{
pageWidth = eval[ARGS@1]
pageHeight = eval[ARGS@2]
}
numChars = digits + 1 // Account for decimal point
if eval["FrinkGeneration[]"] == 0
println["""Note: this program will be orders of magnitude faster with
Frink:The Next Generation, available at:
https://frinklang.org/experimental.html
"""]
args = [["pageWidth", pageWidth], ["pageHeight", pageHeight], ["numChars", numChars]]
println[join["\n", layout.solveAll[]]]
charsPerLine = ceil[positive[eval[layout.solveForValues["charsPerLine", args]]]@0]
println["Chars per line: $charsPerLine"]
lines = ceil[numChars/charsPerLine]
println["Lines: $lines"]
pi = Pi.getPi[digits]
piStr = toString[pi]
println["Pi calculated to $digits digits"]
g = new graphics[]
g.font["Monospaced", 1]
line = 0
for pos = 0 to length[piStr]-1 step charsPerLine
{
sub = substringLen[piStr, pos, charsPerLine]
g.text[sub, 0, line, "left", "center"]
line = line + .9
}
g.show[]
filename = "piPoster$digits.svg"
g.write[filename, 1000, 1000]
//browse[ filename]
Download or view piPoster.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 20218 days, 0 hours, 8 minutes ago.