Hobby

Hobby

Hobby is a Lua scripting tool for creating SVG vector graphics using the Hobby-Knuth smooth curve algorithm. It is named after John Hobby, the developer of MetaPost.

Installation

Homebrew (macOS/Linux)

brew install boxesandglue/tap/hobby

Go

go install github.com/boxesandglue/hobby/cmd/hobby@latest

Binary Downloads

Download binaries from the releases page.

Quick Start

Create a file hello.lua:

local h = require("hobby")

-- Create 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)

-- Build a smooth curved path
local path = h.path()
    :moveto(z0)
    :curveto(z1)
    :curveto(z2)
    :curveto(z3)
    :cycle()
    :stroke("blue")
    :build()

-- Output to SVG
h.svg()
    :padding(5)
    :add(path)
    :write("hello.svg")

Run with:

hobby hello.lua

This produces:

Hello example

Documentation

The Hobby Algorithm

The Hobby-Knuth algorithm computes smooth Bézier curves that pass through a set of points. Unlike simple spline interpolation, it produces aesthetically pleasing curves by choosing optimal tangent directions at each point.

The algorithm was developed by John Hobby for MetaPost and is described in his paper “Smooth, Easy to Compute Interpolating Splines” (1986).