Lua bindings for the mpgo MetaPost curve library. Named after John Hobby, the developer of MetaPost and the Hobby-Knuth smooth curve algorithm.
brew install boxesandglue/tap/hobbygo install github.com/boxesandglue/hobby/cmd/hobby@latestDownload binaries from the releases page.
hobby script.luaA smooth curve through five points using the Hobby algorithm:
local h = require("hobby")
-- Create some points
local z0 = h.point(0, 0)
local z1 = h.point(60, 40)
local z2 = h.point(40, 90)
local z3 = h.point(10, 70)
local z4 = h.point(30, 50)
-- Build a closed curved path
local path = h.path()
:moveto(z0)
:curveto(z1)
:curveto(z2)
:curveto(z3)
:curveto(z4)
:cycle()
:build()
-- Create SVG and add the path
h.svg()
:padding(5)
:add(path)
:write("simple.svg")Predefined shapes with various transformations:
local h = require("hobby")
-- Original circle
local circle = h.fullcircle():scaled(20):shifted(30, 80):stroke("black")
-- xscaled (stretched horizontally)
local xscaled = h.fullcircle():scaled(20):xscaled(2):shifted(90, 80):stroke("blue")
-- yscaled (stretched vertically)
local yscaled = h.fullcircle():scaled(20):yscaled(2):shifted(150, 80):stroke("red")
-- slanted (sheared)
local slanted = h.unitsquare():scaled(30):slanted(0.5):shifted(30, 20):stroke("green")
-- Combination
local combo = h.fullcircle()
:scaled(20)
:xscaled(1.5)
:yscaled(0.7)
:slanted(0.3)
:shifted(130, 30)
:stroke("purple")
-- Output to SVG
h.svg()
:padding(10)
:add(circle)
:add(xscaled)
:add(yscaled)
:add(slanted)
:add(combo)
:write("transforms.svg")Full documentation is available at boxesandglue.dev/hobby.
BSD-3-Clause. See LICENSE.