Created
February 21, 2018 17:45
-
-
Save cormullion/99b03b2e8c202077e2a4aae3e296ed6d to your computer and use it in GitHub Desktop.
pi day image
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
| # draw pi digits up to Feynman point to give illusion of rounding at 999999 | |
| 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 = a ÷ b, a1 ÷ b1 | |
| while (d == d1) && (n > 0) | |
| push!(result, d) | |
| n -= 1 | |
| a, a1 = 10(a % b), 10(a1 % b1) | |
| d, d1 = a ÷ b, a1 ÷ b1 | |
| end | |
| end | |
| return result | |
| end | |
| function draw() | |
| pd = pidigits(777) # (21 by 37 up to Feynman point) | |
| w, h = 600, 600 ÷ golden | |
| pl = box(O, w, h, vertices=true) | |
| backgroundmesh = mesh(pl, [ | |
| Colors.RGB(0.15, 0.05, 0.1), | |
| Colors.RGB(0.1, 0.1, 0.25), | |
| Colors.RGB(0.2, 0.3, 0.5), | |
| Colors.RGB(0.1, 0.1, 0.15), | |
| ]) | |
| @png begin | |
| setmesh(backgroundmesh) | |
| poly(pl, :fill) | |
| fontsize(22) | |
| fontface("FiraMonoOT-Bold") | |
| tiles = Tiler(w, h, 21, 37, margin = 5) | |
| for (pos, n) in tiles | |
| @layer begin | |
| translate(pos) | |
| # random gradient color mesh | |
| setmesh(mesh(box(O, tiles.tilewidth, tiles.tileheight, vertices=true), [ | |
| Colors.RGB(rand(0.3:0.1:1.0, 3)...), | |
| Colors.RGB(rand(0.3:0.1:1.0, 3)...), | |
| Colors.RGB(rand(0.3:0.1:1.0, 3)...), | |
| Colors.RGB(rand(0.3:0.1:1.0, 3)...) | |
| ])) | |
| # Feynman point yet? | |
| n > 768 ? text(".", halign=:center, valign=:middle) : | |
| text(string(pd[n]), halign=:center, valign=:middle) | |
| end | |
| end | |
| setmesh(mesh(pl, [ | |
| Colors.RGBA(0.2, 1.0, 0.5, .4), | |
| Colors.RGBA(sethue("orange")..., .4), | |
| "red", | |
| Colors.RGBA(0.8, 1.0, 0.3, .4), | |
| ])) | |
| fontface("BernhardStd-BoldCondensed") | |
| fontsize(w) | |
| text("π", halign=:center, valign=:middle) | |
| end 600 (600 ÷ golden) | |
| end | |
| draw() |
Author
cormullion
commented
Feb 21, 2018

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment