Skip to content

Instantly share code, notes, and snippets.

@cormullion
Created November 9, 2021 10:34
Show Gist options
  • Save cormullion/b1f11b0eaba45252a11269e893e88df5 to your computer and use it in GitHub Desktop.
Save cormullion/b1f11b0eaba45252a11269e893e88df5 to your computer and use it in GitHub Desktop.
Julia Graphs icon
using Luxor
using Graphs
using Colors
function lighten(col::Colorant, f)
c = convert(RGB, col)
return RGB(f * c.r, f * c.g, f * c.b)
end
function julia_sphere(pt::Point, w, col::Colorant;
action = :none)
setmesh(mesh(
makebezierpath(box(pt, w * 1.5, w * 1.5)),
[lighten(col, .5),
lighten(col, 1.75),
lighten(col, 1.25),
lighten(col, .6)]))
circle(pt, w, action)
end
function draw_edge(pt1, pt2)
for k in 0:0.1:1
setline(rescale(k, 0, 1, 25, 1))
sethue(lighten(colorant"grey50", rescale(k, 0, 1, 0.5, 1.5)))
setopacity(rescale(k, 0, 1, 0.5, 0.75))
line(pt1, pt2, :stroke)
end
end
function main(fname)
Drawing(600, 600, fname)
origin()
squircle(O, 294, 294, :clip, rt=0.2)
background("black")
colors = [Luxor.julia_red, Luxor.julia_green, Luxor.julia_purple, Luxor.julia_blue]
# make some nodes
outerpts = ngonside(O, 450, 4, π/4, vertices=true)
innerpts = ngonside(O, 150, 4, π/2, vertices=true)
pts = vcat(outerpts, innerpts)
# build graph
g = SimpleGraph([
Edge(1,2),
Edge(2,3),
Edge(3,4),
Edge(1,4),
Edge(5,6),
Edge(6,7),
Edge(7,8),
Edge(5,8),
Edge(1,5),
Edge(2,6),
Edge(3,7),
Edge(4,8),
])
# draw edges
for (n, e) in enumerate(edges(g))
s, d = src(e), dst(e)
draw_edge(pts[s], pts[d])
end
# draw nodes
for (n, v) in enumerate(vertices(g))
s = distance(O, pts[v])
if s < 200 # inner
col = colors[mod1(n, end)]
else # outer, shift color by 1
col = colors[mod1(n - 1, end)]
end
julia_sphere(pts[v], rescale(s, 100, 320, 55, 45), RGB(col...), action=:fill)
end
finish()
preview()
end
main("/tmp/julia-graphs.png")
# run(`svgo -i /private/tmp/julia-graphs.svg -o /private/tmp/julia-graphs-opt.svg`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment