piPoster.frink

View or download 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 pi.frink

symbolicMode[true]

layout = new System[[pageWidth pageHeight === charHeight charWidth numChars,
                     charWidth === 6/10 charHeight,
                     lines === pageHeight / charHeight,
                     charsPerLine === numChars / lines],
                    []]

digits = 10000

// Read number of digits from command-line argument if there is one.
if length[ARGS] > 0
   digits = eval[ARGS@0]

numChars = digits + 1   // Account for decimal point

args = [["pageWidth", 8 in], ["pageHeight", 10.5 in], ["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]



View or download 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 17989 days, 13 hours, 11 minutes ago.