Published
Edited
Sep 29, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function koch(p0, p1, limit) {
const dx = p1[0] - p0[0];
const dy = p1[1] - p0[1];

const dist = Math.sqrt(dx * dx + dy * dy);
const unit = dist / 3;
const angle = Math.atan2(dy, dx);

const pA = [p0[0] + dx / 3, p0[1] + dy / 3];
const pC = [p1[0] - dx / 3, p1[1] - dy / 3];
const pB = [
pA[0] + Math.cos(angle - Math.PI / 3) * unit,
pA[1] + Math.sin(angle - Math.PI / 3) * unit
];

if (limit > 0) {
return [
koch(p0, pA, limit - 1),
koch(pA, pB, limit - 1),
koch(pB, pC, limit - 1),
koch(pC, p1, limit - 1)
].flat();
}
return [p0, pA, pB, pC, p1];
}
Insert cell
Insert cell
Insert cell
pairUp([1, 2, 3, 4, 5, 6])
Insert cell
pairUp = (input) => {
const result = [];
for (let i = 0; i < input.length; i++) {
result[i] =
i === input.length - 1 ? [input[i], input[0]] : [input[i], input[i + 1]];
}
return result;
}
Insert cell
strokWidth = 1
Insert cell
generatePathD = d3.line() //.curve(d3.curveCatmullRomClosed.alpha(1))
Insert cell
palette = ({
bg: `hsl(0,0%,95%)`,
fg: `hsl(0,0%,5%)`,
debug: `hsl(300, 100%, 50%)`
})
Insert cell
maxSize = Math.min(width, height)
Insert cell
margin = maxSize / 10
Insert cell
size = maxSize - 2 * margin
Insert cell
marginX = (width - size) / 2
Insert cell
marginY = (height - size) / 2
Insert cell
height = Math.floor((width * 9) / 16)
Insert cell
svg = htl.svg
Insert cell
import { distance, angleOfInclination } from "@saneef/helper-functions-geometry"
Insert cell
import { CSMath as math, CSRandom as random } from "@saneef/canvas-sketch-util"
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more