Last active
December 30, 2018 17:59
-
-
Save cormullion/df90d226ece8395115aa4ed38c8a9e45 to your computer and use it in GitHub Desktop.
pi-day-draw-pi-with-circles.jl
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
using Luxor | |
# drawing pi with circles, rather than drawing circles with pi | |
function perimeterize(s, n) | |
# center it | |
te = textextents(s) | |
move(-te[3]/2, te[4]/2) | |
textpath(s) | |
p = pathtopoly()[1] | |
pathpattern = Point[] | |
pdistances = polydistances(p) | |
for i in 0.0:n:1.0 | |
pp = polyportion(p, i, closed=true, pdist=pdistances) | |
push!(pathpattern, pp[end]) | |
end | |
return pathpattern | |
end | |
function circlesaroundpoly(pgon) | |
pl = length(pgon) | |
sethue("white") | |
setline(0.1) | |
setmode("xor") | |
@inbounds for n in 1:pl | |
p1 = pgon[mod1(n, pl)] | |
p2 = pgon[mod1(n + 1, pl)] | |
p3 = pgon[mod1(n + 2, pl)] | |
(c, r) = center3pts(p1, p2, p3) | |
# avoid those wacky geometry errors... | |
5 < r < 5000 && circle(c, r, :stroke) | |
end | |
end | |
@png begin | |
background(0.1, 0.1, 0.25) | |
fontface("ArnoldBoecklinStd") | |
fontsize(480) | |
pathpattern = perimeterize("π", 0.001) | |
circlesaroundpoly(pathpattern) | |
end 600 300 |
Author
cormullion
commented
Feb 21, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment