Last active
November 22, 2021 22:48
-
-
Save cormullion/e979d819e478da73280faaeb67490888 to your computer and use it in GitHub Desktop.
pi digits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
using Luxor | |
function pidigits(n) | |
result = Int[] | |
k, a::BigInt, b::BigInt, a1::BigInt, b1::BigInt = 2, 4, 1, 12, 4 | |
while n > 0 | |
p, q, k = k * k, 2k + 1, k + 1 | |
a, b, a1, b1 = a1, b1, p * a + q * a1, p * b + q * b1 | |
d, d1 = div(a, b), div(a1, b1) | |
while (d == d1) && (n > 0) | |
push!(result, d) | |
n -= 1 | |
a, a1 = 10 * (a % b), 10 * (a1 % b1) | |
d, d1 = div(a, b), div(a1, b1) | |
end | |
end | |
return result | |
end | |
function drawjulia() | |
gsave() | |
scale(2, 2) | |
translate(-165, -120) | |
sethue("grey80") | |
setopacity(0.4) | |
julialogo(color=false) | |
grestore() | |
end | |
function draw() | |
Drawing(1000, 500, "/tmp/pi.png") | |
background("royalblue4") | |
origin() | |
drawjulia() | |
fontface("Georgia-Bold") | |
tiles = Tiler(1000, 500, 50, 100, margin=5) | |
thedigitsofpi = pidigits(50 * 100) | |
fontsize(10) | |
setopacity(0.8) | |
setline(0.25) | |
for (pos, n) in tiles | |
sethue(0.7, rand(), rand(0.0:0.1:0.4)) | |
thedigit = thedigitsofpi[n] | |
n == 1 && text(string(thedigit, "."), pos, halign=:center) # dat decimal point doe | |
n > 1 && text(string(thedigit), pos, halign=:center) | |
end | |
finish() | |
preview() | |
end | |
draw() |
Author
cormullion
commented
Nov 21, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment