Codeboard.
Technical referenceAPI signatures

Drawing and math API

Named functions are imported from codeboard-studio. See drawing, brushes, and math for use and constraints. Built-in brushes are brushes.roughPencil, cleanInk, shadeBrush, charcoal, and softEraser. brushParameterSchema is JSON Schema data; production.createBrush validates a preset when adding it to a project.

Use the signatures below to check arguments and return types. A value after = is the default; ? marks an optional input. Named data shapes are listed in API types.

line

Code
function line(from: PointLike, to: PointLike, samples = 24): Point[];

cubic

Code
function cubic(p0: PointLike, p1: PointLike, p2: PointLike, p3: PointLike, samples = 48): Point[];

catmullRom

Code
function catmullRom(points: PointLike[], samplesPerSegment = 12, tension = 0.5): Point[];

ellipse

Code
function ellipse(cx: number, cy: number, rx: number, ry: number, options: {
    samples?: number;
    pressure?: number;
    rotation?: number;
} = {}): Point[];

translate

Code
function translate(points: Point[], x: number, y: number): Point[];

scale

Code
function scale(points: Point[], scaleX: number, scaleY = scaleX, origin = { x: 0, y: 0 }): Point[];

withPressure

Code
function withPressure(points: Point[], pressure: number | ((t: number) => number)): Point[];

mirrored

Code
function mirrored(points: Point[], axisX: number): Point[];

hatchPolygon

Code
function hatchPolygon(polygon: PointLike[], options: {
    angle?: number;
    spacing?: number;
    pressure?: number;
    jitter?: number;
    seed?: number;
    maxSamples?: number;
} = {}): Point[][];

pathCommands

Code
/** SVG's absolute M/L/C/Q/Z subset, retained as editable contour commands. */
export function pathCommands(source: string): PathCommand[];

samplePath

Code
/** Sample separate pen-down paths. The original editable contour commands remain untouched. */
export function samplePath(commands: readonly PathCommand[], options: PathSamplingOptions = {}): Point[][];

splitPathSegment

Code
/** Insert a knot using de Casteljau subdivision; retain editable curve commands. */
export function splitPathSegment(commands: readonly PathCommand[], index: number, t = 0.5): PathCommand[];

combinePaths

Code
function combinePaths(a: readonly PathCommand[], b: readonly PathCommand[], operation: PathBooleanOperation): PathCommand[];

pathBounds

Code
function pathBounds(commands: readonly PathCommand[]): { left: number; top: number; right: number; bottom: number; width: number; height: number; } | null;

pathContains

Code
function pathContains(commands: readonly PathCommand[], x: number, y: number): boolean;

customizeBrush

Code
function customizeBrush(base: BrushPreset, changes: Partial<Omit<BrushPreset, "dynamics">> & {
    dynamics?: Partial<BrushPreset["dynamics"]>;
}): BrushPreset;

brushTipFromFunction

Code
function brushTipFromFunction(width: number, height: number, sample: (x: number, y: number) => number, options: {
    angle?: number;
    rotationMode?: "fixed" | "stroke" | "stylus";
} = {}): BrushTip;

importBrushResource

Code
async function importBrushResource(path: string, options: ImportOptions): Promise<BrushImportReport>;

importBrushResourceBuffer

Code
async function importBrushResourceBuffer(data: Buffer, name: string, options: ImportOptions): Promise<BrushImportReport>;

brushFromResource

Code
/** Explicitly reauthor a resource for this engine; never promises source-application parity. */
export function brushFromResource(resource: BrushResource, settings: Omit<BrushPreset, "tip">): BrushPreset;

renderBrushSwatch

Code
async function renderBrushSwatch(brush: BrushPreset, options: {
    color?: string;
    background?: string;
} = {}): Promise<Buffer>;

createPixels

Code
function createPixels(width: number, height: number): PixelBuffer;

readPixelRegion

Code
function readPixelRegion(image: PixelBuffer, region: PixelRegion): PixelBuffer;

writePixelRegion

Code
function writePixelRegion(image: PixelBuffer, x: number, y: number, patch: PixelBuffer): void;

comparePixels

Code
/** Compare visible premultiplied RGBA, ignoring hidden RGB under zero alpha. */
export function comparePixels(before: PixelBuffer, after: PixelBuffer, options: {
    threshold?: number;
} = {}): PixelComparison;

decodePixels

Code
async function decodePixels(bytes: Uint8Array): Promise<PixelBuffer>;

encodePixels

Code
async function encodePixels(image: PixelBuffer): Promise<Buffer>;

importPSD

Code
/** Import a bounded RGB8 pixel-layer PSD without mutating a project or using its merged preview. */
export function importPSD(input: Uint8Array, options: PSDImportOptions): PSDImportResult;

polygonPixelSelection

Code
function polygonPixelSelection(width: number, height: number, points: Pick<Point, "x" | "y">[], fillRule: "nonzero" | "evenodd" = "nonzero"): PixelSelection;

colorPixelSelection

Code
/** Four-connected flood or all matching pixels, measured in premultiplied RGBA byte units. */
export function colorPixelSelection(image: PixelBuffer, x: number, y: number, options: {
    tolerance?: number;
    contiguous?: boolean;
} = {}): PixelSelection;

combinePixelSelections

Code
function combinePixelSelections(a: PixelSelection, b: PixelSelection, operation: "union" | "intersect" | "subtract"): PixelSelection;

invertPixelSelection

Code
function invertPixelSelection(selection: PixelSelection): PixelSelection;

featherPixelSelection

Code
/** Gaussian coverage feathering in source-pixel units; boundary samples repeat edge coverage. */
export async function featherPixelSelection(selection: PixelSelection, sigma: number): Promise<PixelSelection>;

fillPixels

Code
/** Apply coverage without flattening the source surface or its later paint strokes. */
export function fillPixels(image: PixelBuffer, color: PixelColor, options: {
    selection?: PixelSelection;
    mode?: "source-over" | "copy" | "destination-out" | "source-atop";
} = {}): void;

multiplyMatrices

Code
/** Composition A × B applies B first, then A. */
export function multiplyMatrices(left: readonly number[], right: readonly number[]): AffineMatrix;

matrixFromTransform

Code
function matrixFromTransform(value: Partial<Transform>, pivot: Pivot = { x: 0, y: 0 }): AffineMatrix;

invertMatrix

Code
function invertMatrix(value: readonly number[]): AffineMatrix;

transformPoint

Code
function transformPoint(value: readonly number[], point: Pick<Point, "x" | "y">): {
    x: number;
    y: number;
};

solveTwoBoneIK

Code
function solveTwoBoneIK(origin: {
    x: number;
    y: number;
}, target: {
    x: number;
    y: number;
}, upperLength: number, lowerLength: number, bend: 1 | -1 = 1): TwoBoneSolution;

On this page