Published
Edited
Sep 29, 2022
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
generateCircles = (pts, opts) => {
const { fill, r, xShift, yShift, skipIf, mixBlendMode } = Object.assign(
{
fill: "white",
r: 1,
xShift: 0,
yShift: 0,
skipIf: 1
},
opts
);
const circle = pts.map(([cx, cy, skip]) =>
skip === skipIf
? null
: svg`<circle cx=${cx + xShift} cy=${
cy + yShift
} r=${r} fill=${fill} style=${{ mixBlendMode }}>`
);

return svg`<g>${circle}</g>`;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
samplingFunction = distribution === "Poisson" ? poissonSampling : gridSampling
Insert cell
gridSampling(numOfPts, width, height)
Insert cell
function* gridGenerator(n, width, height) {
let d = width / Math.sqrt((n * height) / width);
let [x, y] = [d / 2, d / 2];
while (n-- > 0) {
yield [x, y];
x += d;
if (x >= width) {
x = d / 2;
y += d;
}
}
}
Insert cell
gridSampling = (n, width, height) => {
let pts = [];
for (let p of gridGenerator(n, width, height)) {
pts.push(p);
}

return pts;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more