Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created March 12, 2025 18:50
Show Gist options
  • Save jkrumbiegel/d20453443540a135027aa6aa915b9c23 to your computer and use it in GitHub Desktop.
Save jkrumbiegel/d20453443540a135027aa6aa915b9c23 to your computer and use it in GitHub Desktop.
Makie hexagon axis plot
hexradius = 45
hexpoly(p, hexradius) = Makie.Polygon(Ref(p) .+ Point2f[hexradius .* (cos(a), sin(a)) for a in range(pi / 6, 13pi / 6; length=7)[1:6]])
s = Scene(camera = campixel!)
function hex_center(q::Int, r::Int, radius)
# axial coordinates
x = radius * sqrt(3) * (r + q / 2)
y = radius * (3/2) * q
return Point2f(x, y)
end
function hex_ax!(scene, p, hexradius; padding = 0.1 * hexradius)
poly!(scene, hexpoly(p, hexradius), transformation = (; translation = (0, 0, -100)))
apothem = hexradius * sqrt(3) / 2
r = Rect2f(
p .- Point2f(apothem, hexradius/2) .+ padding,
Vec2f(2*apothem, hexradius) .- 2 .* padding,
)
ax = Axis(scene, bbox = r)
hidedecorations!(ax)
hidespines!(ax)
return ax
end
for q in -2:2, r in -2:2
p = hex_center(q, r, hexradius + 3)
p += Point2f(s.viewport[].origin .+ 0.5 .* s.viewport[].widths)
ax = hex_ax!(s, p, hexradius)
lines!(ax, cumsum(randn(100)), color = :black)
reset_limits!(ax)
ax.title = "$q/$r"
ax.backgroundcolor = (:black, 0.1)
end
s
@jkrumbiegel
Copy link
Author

image

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