Public
Edited
Aug 28, 2023
Insert cell
Insert cell
golden_ratio = (1 + Math.sqrt(5)) / 2
Insert cell
<svg ${size} viewBox="0 0 ${size.width} ${size.height}" id="spiralContainer">
<rect width="100%" height="100%" fill="hsl(216deg 100% 13%)" />
<!-- <circle width="50%" height="50%" fill="hsl(216deg 50% 13%)" /> -->
${generateSpiral(0.4)}
</svg>
Insert cell
Insert cell
function generateSpiral(ratio) {
const svgNS = "http://www.w3.org/2000/svg";
const svgWidth = 500;
const svgHeight = 500;
const centerX = svgWidth / 2;
const centerY = svgHeight / 2;
const numTurns = 10; // Number of turns in the spiral
const numPoints = 100; // Number of points to draw

const svg = document.createElementNS(svgNS, "svg");
svg.setAttributeNS(null, "width", svgWidth);
svg.setAttributeNS(null, "height", svgHeight);

const path = document.createElementNS(svgNS, "path");
let d = "M"; // Path data string

for (let i = 0; i <= numPoints; i++) {
const angle = (i / numPoints) * (numTurns * 2 * Math.PI);
const radius = ratio * angle;

const x = centerX + radius * Math.cos(angle);
const y = centerY + radius * Math.sin(angle);

d += `${x},${y} `;
}

path.setAttributeNS(null, "d", d);
path.setAttributeNS(null, "fill", "none");
path.setAttributeNS(null, "stroke", "black");

svg.appendChild(path);

return svg;
}
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