where algorithms meet ink

The Algorithm

function drawSpirograph(R, r, d) {
const points = [];
for (let t = 0; t < 2 * Math.PI * 20; t += 0.01) {
const x = (R - r) * Math.cos(t) + d * Math.cos((R - r) / r * t);
const y = (R - r) * Math.sin(t) - d * Math.sin((R - r) / r * t);
points.push({ x, y });
}
return toSVGPath(points);
}

Every line is a decision. Every curve, an equation made visible.