Last active
January 15, 2021 11:14
-
-
Save cormullion/b4c25d4209caf9f0ec6e8ac46f45df42 to your computer and use it in GitHub Desktop.
Make geostats logo in Luxor, using the awesome Contours.jl
This file contains 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, Contour, Images | |
function geostats(s) | |
Δ = s/500 # scale factor, original design was 500units | |
circle(O, 245Δ, :clip) | |
sethue("white") | |
circle(O, 245Δ, :fill) | |
# generate contours from image | |
pwd() | |
i = load(string(@__DIR__, "/geostats-contours.png")) | |
img = imresize(i, ratio=1.75) | |
H, W = size(img) | |
imgg = imfilter(img, Kernel.gaussian(15)) | |
x = -W/2.0:W/2.0 - 1 # W elements | |
y = -H/2.0:H/2.0 - 1 # H elements | |
z = Float64.(Gray.(imgg)) | |
# just two contours required | |
clevels = Contour.contourlevels(z, 2) | |
contourlines = contours(x, y, z, clevels) | |
# draw the contours | |
@layer begin | |
scale(Δ) | |
setline(8Δ) | |
for (n, cl) in enumerate(levels(contourlines)) | |
for l in lines(cl) | |
# convert contour points to Luxor coords | |
sethue("black") | |
pgon = map(p -> Point(p[2], p[1]), zip(coordinates(l)...)) | |
poly(pgon, :stroke) | |
# optional coloring? | |
setgray([.6, .8][n]) | |
poly(pgon, :fill, close=true) | |
end | |
end | |
end | |
clipreset() | |
sethue("black") | |
setline(8Δ) | |
circle(O, 245Δ, :stroke) | |
sethue(Luxor.julia_purple) | |
circle(Point(190, 120)Δ, 55Δ, :fill) | |
sethue(Luxor.julia_green) | |
circle(Point(70, -55)Δ, 50Δ, :fill) | |
sethue(Luxor.julia_red) | |
circle(Point(-180, 12)Δ, 40Δ, :fill) | |
end | |
function logo(s, fname) | |
Drawing(s, s, fname) | |
origin() | |
geostats(s) | |
finish() | |
preview() | |
end | |
function logotext(w, h, fname) | |
Drawing(w, h, fname) | |
#background("white") | |
origin() | |
table = Table([h], [h, w - h]) | |
@layer begin | |
translate(table[1]) | |
geostats(h) | |
end | |
@layer begin | |
translate(table[2]) | |
sethue("black") | |
# find all fonts available on Linux with `fc-list | -f 2 -d ":"` | |
fontface("Julius Sans One") | |
fontsize(h/2.5) | |
text("GeoStats.jl", halign=:center, valign=:middle) | |
end | |
finish() | |
preview() | |
end | |
for ext in [".svg", ".png"] | |
logo(120, "/tmp/geostatslogo"*ext) | |
logotext(350, 100, "/tmp/getstatslogo-text"*ext) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the background for the contours...