@thi.ng/geom-fuzz
Version:
Highly configurable, fuzzy line & polygon creation with presets and composable fill & stroke styles. Canvas & SVG support
26 lines (25 loc) • 718 B
JavaScript
import { asCubic } from "@thi.ng/geom/as-cubic";
import { group } from "@thi.ng/geom/group";
import { pathFromCubics } from "@thi.ng/geom/path-from-cubics";
import { polygon } from "@thi.ng/geom/polygon";
import { jitterPoints } from "./points.js";
const fuzzyPoly = (pts, attribs = {}, opts = {}) => {
opts = {
num: 2,
jitter: 2,
...opts,
curve: { mode: "break", ...opts.curve }
};
const acc = group(attribs, []);
for (; --opts.num >= 0; ) {
const poly = polygon(jitterPoints(pts, opts.jitter));
acc.children.push(pathFromCubics(asCubic(poly, opts.curve)));
if (!opts.num && opts.fill) {
acc.children.push(opts.fill(poly));
}
}
return acc;
};
export {
fuzzyPoly
};