docs / Parametrize

Parametrize

Declare editable dimensions and do arithmetic on them (JS operators throw on a ParamRef).

param() returns a ParamRef, not a number. JS operators throw on one, so arithmetic goes through .subtract() and .multiply().

const width = param('width', 60);
const wall = param('wall', 4);

const inner = width.subtract(wall.multiply(2));

return box(width, 40, 12).subtract(
  box(inner, 30, 8).translate(wall, 5, 4),
);
JavaScript is off — the listing above is the whole example.

Calls

CallWhat it does
param(name, defaultValue, meta?) => ParamRefDeclare a symbolic editable parameter.
params(decl) => { [name]: ParamRef }Batched form of param() — declare many params at once.
ParamRef.add(other: number | ParamRef<number>) => ParamRef<number>Build a ParamRef whose value equals this ParamRef plus other.
Shape.subtract(...others) => ShapeBoolean difference (this minus others).
ParamRef.subtract(other: number | ParamRef<number>) => ParamRef<number>Build a ParamRef whose value equals this ParamRef minus other.
ParamRef.multiply(other: number | ParamRef<number>) => ParamRef<number>Build a ParamRef whose value equals this ParamRef times other.
ParamRef.divide(other: number | ParamRef<number>) => ParamRef<number>Build a ParamRef whose value equals this ParamRef divided by other.
ParamRef.negate() => ParamRef<number>Build a ParamRef whose value equals the unary negation of this ParamRef.