Codeboard.

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 validates a preset.

Parameter declarations below are extracted from the current source. A value after = is the default; ? marks an optional input. Named data shapes are listed in API types.

line

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

cubic

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

catmullRom

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

ellipse

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

translate

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

scale

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

withPressure

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

hatchPolygon

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

mirrored

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

pathCommands

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

samplePath

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

splitPathSegment

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

combinePaths

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

pathBounds

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

pathContains

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

customizeBrush

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

brushTipFromFunction

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

importBrushResource

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

importBrushResourceBuffer

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

brushFromResource

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

renderBrushSwatch

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

createPixels

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

readPixelRegion

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

writePixelRegion

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

decodePixels

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

encodePixels

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

comparePixels

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

polygonPixelSelection

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

colorPixelSelection

/** 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

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

invertPixelSelection

function invertPixelSelection(selection: PixelSelection): PixelSelection;

featherPixelSelection

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

fillPixels

/** 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

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

matrixFromTransform

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

invertMatrix

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

transformPoint

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

solveTwoBoneIK

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

On this page