Skip to content

Commit

Permalink
update links, add example
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Apr 21, 2022
1 parent 1912a98 commit eb25c4c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Karnak.jl is a small extension for the Luxor.jl package to
help with constructing graph-style drawings.

Karnak relies on [Graphs.jl](https://juliagraphs.org/Graphs.jl/) for graph construction, and
Karnak relies on [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) for graph construction, and
on [NetworkLayout.jl](https://juliagraphs.org/NetworkLayout.jl/) for graph layout.

The focus in Karnak, unlike other graph visualization
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Karnak.jl is a small extension for the Luxor.jl package to
help with constructing graph-style drawings.

Karnak relies on
[Graphs.jl](https://juliagraphs.org/Graphs.jl/) for graph
[Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) for graph
construction, and on
[NetworkLayout.jl](https://juliagraphs.org/NetworkLayout.jl/)
for graph layout.
Expand Down
57 changes: 57 additions & 0 deletions examples/julia-graphs-logo.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Graphs
using Karnak
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

outerpts = ngonside(O, 450, 4, π/4, vertices=true)
innerpts = ngonside(O, 150, 4, π/2, vertices=true)
pts = vcat(outerpts, innerpts)
colors = map(c -> RGB(c...), [Luxor.julia_blue, Luxor.julia_red, Luxor.julia_green, Luxor.julia_purple])

Drawing(600, 600, "/tmp/julia-graphs.svg")
origin()
squircle(O, 294, 294, :clip, rt=0.2)
sethue("black")
paint()
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),
])

drawgraph(Graph(g),
layout=pts,
vertexfunction = (v, c) -> begin
d = distance(O, c[v])
d > 200 ? k = 0 : k = 1
julia_sphere(c[v], rescale(d, 0, 200, 52, 50), colors[mod1(v + k, 4)], action=:fill)
end,
edgefunction = (k, s, d, f, t) -> draw_edge(f, t)
)
finish()
preview()
# run(`svgo -i /private/tmp/julia-graphs.svg -o /private/tmp/julia-graphs-opt.svg`)

0 comments on commit eb25c4c

Please sign in to comment.