// 003 - Superformula Bloom (organic)
// 1:1 Original algorithm engine source
function createSuperformulaBloom() {
return {
setup() {
},
render(context, timeState, params) {
const { ctx, width, height } = context;
const t = timeState.time * Number(params.speed || 0.8);
const m = Number(params.symmetry || 6) + Math.sin(t * 0.5) * 2;
const n1 = Number(params.form1 || 0.3) + Math.sin(t * 0.8) * 0.15;
const n2 = Number(params.form2 || 1.7) + Math.cos(t * 0.6) * 0.5;
const n3 = Number(params.form3 || 1.7) + Math.sin(t * 0.7) * 0.5;
const a = 1;
const b = 1;
ctx.fillStyle = "rgba(8, 9, 13, 0.2)";
ctx.fillRect(0, 0, width, height);
const cx = width * 0.5;
const cy = height * 0.5;
const scale = Math.min(width, height) * 0.32;
const steps = 720;
for (let layer = 0; layer < 4; layer++) {
const layerScale = scale * (1 - layer * 0.22);
const layerOffset = layer * 0.4 + t * 0.3;
ctx.beginPath();
for (let i = 0; i <= steps; i++) {
const phi = i / steps * Math.PI * 2;
const part1 = Math.pow(Math.abs(Math.cos(m * phi / 4) / a), n2);
const part2 = Math.pow(Math.abs(Math.sin(m * phi / 4) / b), n3);
const r = Math.pow(part1 + part2, -1 / n1);
const px = cx + r * layerScale * Math.cos(phi + layerOffset);
const py = cy + r * layerScale * Math.sin(phi + layerOffset);
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
}
ctx.closePath();
const hue = (layer * 50 + t * 30 + 300) % 360;
ctx.strokeStyle = hsla(hue, 85, 65, 0.7);
ctx.lineWidth = 2 - layer * 0.3;
ctx.stroke();
}
}
};
}
// Default parameters from content metadata
const defaultParams = [
{
"key": "symmetry",
"label": "Rotational Symmetry (m)",
"type": "range",
"min": 2,
"max": 16,
"step": 1,
"defaultValue": 6,
"description": "Number of morphological petals"
},
{
"key": "form1",
"label": "Curvature Exponent (n1)",
"type": "range",
"min": 0.1,
"max": 1,
"step": 0.05,
"defaultValue": 0.3,
"description": "Overall boundary sharpness"
},
{
"key": "speed",
"label": "Morph Speed",
"type": "range",
"min": 0.2,
"max": 2,
"step": 0.1,
"defaultValue": 0.8,
"description": "Rate of dimensional oscillation"
}
];
if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['superformula-bloom']) {
const inst = typeof createSuperformulaBloom === 'function' ? createSuperformulaBloom() : null;
if (inst && inst.setup) {
inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
}
window.__art_instances['superformula-bloom'] = inst;
}
const instance = window.__art_instances['superformula-bloom'];
if (instance && instance.render) {
instance.render(
{ ctx, width, height, dpr: 1, aspectRatio: width / height },
{ time, deltaTime: dt, frameCount: Math.floor(time * 60), fps: 60 },
defaultParams
);
}