// Generates a bell curve SVG and writes it to _includes/bell-curve.svg // Usage: node scripts/generate-bell-curve.js const fs = require("fs"); const path = require("path"); const width = 600; const height = 300; const padding = { top: 20, right: 20, bottom: 40, left: 20 }; const plotW = width - padding.left - padding.right; const plotH = height - padding.top - padding.bottom; // Standard normal PDF function gaussian(x) { return Math.exp(-0.5 * x * x) / Math.sqrt(2 * Math.PI); } // Generate points from -4 to 4 const steps = 200; const xMin = -4, xMax = 4; const points = []; for (let i = 0; i <= steps; i++) { const x = xMin + (xMax - xMin) * (i / steps); points.push({ x, y: gaussian(x) }); } const yMax = gaussian(0); // peak value function sx(x) { return padding.left + ((x - xMin) / (xMax - xMin)) * plotW; } function sy(y) { return padding.top + plotH - (y / yMax) * plotH; } // Build the curve path const linePath = points.map((p, i) => { const cmd = i === 0 ? "M" : "L"; return `${cmd}${sx(p.x).toFixed(2)},${sy(p.y).toFixed(2)}`; }).join(" "); // Build the filled area path (closed along the baseline) const areaPath = linePath + ` L${sx(xMax).toFixed(2)},${sy(0).toFixed(2)}` + ` L${sx(xMin).toFixed(2)},${sy(0).toFixed(2)} Z`; const svg = ` `; const outPath = path.join(__dirname, "..", "_includes", "bell-curve.svg"); fs.writeFileSync(outPath, svg); console.log(`Wrote ${outPath}`);