SVG output and building blocks

SVG strings

The core renders without React, for Node servers, static sites and build scripts:

import { writeFileSync } from "node:fs";
import { scene, toSvg } from "blobscape";

const svg = toSvg(scene({ seed: "/about", height: 3200, fill: "#fde4ec" }));
writeFileSync("about-background.svg", svg);

The output is one <svg> with one <path> per blob, coordinates rounded to two decimals, so the same input always gives the same bytes.

toSvg optionDefaultMeaning
containerWidthcanvas widthWidth to draw into. Fixed mode centers and crops the canvas; fluid mode scales x positions.
idPrefix"blobscape"Prefix for gradient ids.
precision2Decimal places.

Email: many email clients, Gmail among them, don't display SVG. For email, convert the SVG to PNG first.

Render data

render(scene) returns the same output as plain data (paths and gradient definitions), for drawing with another framework or onto a canvas. <Blobscape> is built on it.

Building blocks

Each stage of the pipeline is exported for advanced use. They take plain data and return plain data.

ExportWhat it does
createRandom(seed)Seeded random generator with independent named sub-streams: random.fork("band", 3).value("x").
generateShape(options, seed)One shape in a unit box, with its bounding radius.
place(options)The positioner: placements for a height, without rendering.
numberSampler, fillSampler, choiceSamplerThe distribution system: per-blob values by index.
parsePath(d), userShape(shape)Parse SVG path data into blobscape's shape format.
toPathData(shape, transform)Shape to SVG path data, with rotation, scale and position applied to the coordinates.
toContainerX(x, width, containerWidth, mode)Maps canvas x to container x for fixed and fluid modes.