API Reference
Complete reference for all hobby functions and methods.
Module Functions
| Function |
Description |
h.point(x, y) |
Create a point |
h.dir(angle) |
Unit vector at angle (degrees) |
h.midpoint(a, b) |
Midpoint of two points |
h.distance(a, b) |
Distance between points |
h.between(a, b, t) |
Point at t along a→b |
h.path() |
Create path builder |
h.fullcircle() |
Unit circle |
h.halfcircle() |
Upper half circle |
h.quartercircle() |
Quarter circle |
h.unitsquare() |
Unit square |
h.svg() |
Create SVG builder |
h.picture() |
Create picture |
h.context() |
Create equation solver |
h.buildcycle(...) |
Build closed region |
Color Functions
| Function |
Description |
h.rgb(r, g, b) |
RGB color (0-1) |
h.gray(value) |
Grayscale (0-1) |
h.color(name) |
CSS color name |
Pen Functions
| Function |
Description |
h.pencircle(size) |
Circular pen |
h.pensquare(size) |
Square pen |
h.penrazor() |
Line pen |
h.penspeck() |
Point pen |
Dash Functions
| Function |
Description |
h.evenly() |
Standard dash pattern |
h.withdots() |
Dotted pattern |
h.dashed(on, off) |
Custom pattern |
Path Builder Methods
Construction
| Method |
Description |
:moveto(point) |
Set start point |
:curveto(point) |
Smooth curve to point |
:lineto(point) |
Straight line to point |
:curvetowithcontrols(pt, c1, c2) |
Bézier with controls |
:cycle() / :close() |
Close path |
:build() |
Solve and return path |
Direction Control
| Method |
Description |
:dir(angle) |
Outgoing direction |
:indir(angle) |
Incoming direction |
Tension Control
| Method |
Description |
:tension(t) |
Both directions |
:outtension(t) |
Outgoing only |
:intension(t) |
Incoming only |
:tensionatleast(t) |
Minimum tension |
:tensioninfinity() |
Infinite (straight) |
Curl Control
| Method |
Description |
:curl(c) |
Both ends |
:outcurl(c) |
Outgoing |
:incurl(c) |
Incoming |
Styling
| Method |
Description |
:stroke(color) |
Stroke color |
:strokewidth(w) |
Stroke width |
:fill(color) |
Fill color |
:pen(pen) |
Set pen |
:dash(pattern) |
Dash pattern |
:evenly() |
Standard dash |
:withdots() |
Dotted |
:arrow() |
End arrow |
:dblarrow() |
Both arrows |
:arrowstyle(len, angle) |
Arrow style |
:linecap(style) |
butt/round/square |
:linejoin(style) |
miter/round/bevel |
Path Methods
Properties
| Property |
Description |
.length |
Number of segments |
.arclength |
Total arc length |
Queries
| Method |
Description |
:pointat(t) |
Point at parameter t |
:directionat(t) |
Tangent at t |
:directiontime(dx, dy) |
Find t where tangent = (dx,dy) |
:directionpoint(dx, dy) |
Point where tangent = (dx,dy) |
:precontrol(t) |
Incoming control point |
:postcontrol(t) |
Outgoing control point |
:arctime(len) |
Parameter at arc length |
:intersectiontimes(path) |
Intersection parameters |
:intersectionpoint(path) |
Intersection point |
Manipulation
| Method |
Description |
:subpath(t1, t2) |
Extract portion |
:reversed() |
Reverse direction |
:cutbefore(path) |
Portion after intersection |
:cutafter(path) |
Portion before intersection |
Transformations
| Method |
Description |
:scaled(s) |
Uniform scale |
:xscaled(s) |
Scale x |
:yscaled(s) |
Scale y |
:shifted(dx, dy) |
Translate |
:rotated(angle) |
Rotate around origin |
:slanted(s) |
Horizontal shear |
:zscaled(a, b) |
Complex multiply |
:rotatedaround(pt, angle) |
Rotate around point |
:scaledaround(pt, s) |
Scale around point |
:reflectedabout(p1, p2) |
Mirror about line |
Styling (on solved paths)
| Method |
Description |
:stroke(color) |
Set stroke |
:strokewidth(w) |
Set width |
:fill(color) |
Set fill |
:pen(pen) |
Set pen |
:dash(pattern) |
Set dash |
:evenly() |
Standard dash |
:withdots() |
Dotted |
:arrow() |
Add arrow |
:dblarrow() |
Add both arrows |
:linecap(style) |
Set cap |
:linejoin(style) |
Set join |
SVG Builder Methods
| Method |
Description |
:add(path) |
Add path |
:addpicture(pic) |
Add picture |
:padding(p) |
Set padding |
:write(filename) |
Write to file |
:tostring() |
Get SVG string |
Picture Methods
| Method |
Description |
:add(path) |
Add path |
:addpicture(pic) |
Add another picture |
:clip(path) |
Set clipping |
:clippath() |
Get clip path |
:paths() |
Get all paths |
:label(text, pt, anchor) |
Add text label |
:dotlabel(text, pt, anchor, color) |
Add label with dot |
:labels() |
Get all labels |
Label Methods
| Method/Property |
Description |
.text |
Label text |
.fontsize |
Font size |
:position() |
Position point |
:setfontsize(size) |
Set font size |
:color() |
Label color |
:setcolor(color) |
Set color |
Anchor values: center, c, left, lft, right, rt, top, bottom, bot, upperleft, ulft, upperright, urt, lowerleft, llft, lowerright, lrt
Context Methods
Point Creation
| Method |
Description |
:known(x, y) |
Known point |
:unknown() |
Unknown point |
:point() |
Alias for unknown |
:points(n) |
Array of unknowns |
Constraints
| Method |
Description |
:eq(v, point) |
v = point |
:eqx(v, x) |
v.x = x |
:eqy(v, y) |
v.y = y |
:eqvar(a, b) |
a = b |
:eqvarx(a, b) |
a.x = b.x |
:eqvary(a, b) |
a.y = b.y |
:midpoint(m, a, b) |
m = midpoint |
:midpointof(a, b) |
Returns midpoint |
:between(p, a, b, t) |
p = t[a,b] |
:betweenat(a, b, t) |
Returns point |
:collinear(p, a, b) |
p on line a-b |
:intersection(p, ...) |
Line intersection |
:intersectionof(...) |
Returns intersection |
:sum(r, a, b) |
r = a + b |
:diff(r, a, b) |
r = a - b |
:scaled(r, v, t) |
r = t * v |
Solving
| Method |
Description |
:solve() |
Solve system |
:path() |
Create linked path |
Variable Methods
| Method/Property |
Description |
.x |
X coordinate |
.y |
Y coordinate |
:xy() |
Returns x, y |
:point() |
As hobby point |
:setx(x) |
Set x |
:sety(y) |
Set y |
:setxy(x, y) |
Set both |