From 809ef10980674b3b4399ee1917297a73ed1fec9c Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 1 Dec 2025 07:09:13 +0000 Subject: [PATCH] Changes --- src/components/FerrersRogersRamanujan.tsx | 99 ++++++++++++++++++++--- 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/src/components/FerrersRogersRamanujan.tsx b/src/components/FerrersRogersRamanujan.tsx index 9f44999..467cf1c 100644 --- a/src/components/FerrersRogersRamanujan.tsx +++ b/src/components/FerrersRogersRamanujan.tsx @@ -13,6 +13,8 @@ const FerrersRogersRamanujan = () => { const [animatingHook, setAnimatingHook] = useState<{ row: number; col: number } | null>(null); const [animationStep, setAnimationStep] = useState(0); const [isAnimating, setIsAnimating] = useState(false); + const [hookColors, setHookColors] = useState([]); + const [baseHue, setBaseHue] = useState(0); useEffect(() => { // Initialize sliders with all zeros @@ -45,6 +47,7 @@ const FerrersRogersRamanujan = () => { setAnimatingHook(null); setAnimationStep(0); setIsAnimating(false); + setHookColors([]); }; const generateRRPartition = () => { @@ -53,11 +56,25 @@ const FerrersRogersRamanujan = () => { return; } + // Pick a random base hue (0-360) + const newBaseHue = Math.floor(Math.random() * 360); + setBaseHue(newBaseHue); + setHookColors([]); setRRPartition([]); setAnimationStep(0); setIsAnimating(true); }; + // Generate muted pastel color for current hook + const generateHookColor = (index: number, total: number) => { + // Move through shades of the base hue + const hueVariation = (index / Math.max(total - 1, 1)) * 60 - 30; // ±30 degrees + const hue = (baseHue + hueVariation + 360) % 360; + const saturation = 45 + (index % 3) * 10; // 45-65% for muted pastels + const lightness = 75 + (index % 2) * 5; // 75-80% for pastels + return `hsl(${hue}, ${saturation}%, ${lightness}%)`; + }; + // Animation effect - traverse main diagonal only useEffect(() => { if (!isAnimating || committedPartition.length === 0) return; @@ -90,7 +107,12 @@ const FerrersRogersRamanujan = () => { } const hookSize = boxesRight + boxesBelow + 1; - // Update RR partition + // Generate color for this hook (estimate total hooks as partition length) + const estimatedTotalHooks = Math.min(partition.length, partition[0] || 0); + const color = generateHookColor(animationStep, estimatedTotalHooks); + + // Update colors and RR partition + setHookColors(prev => [...prev, color]); setRRPartition(prev => [...prev, hookSize]); // Schedule next step @@ -99,9 +121,9 @@ const FerrersRogersRamanujan = () => { }, 500); return () => clearTimeout(timeout); - }, [isAnimating, animationStep, committedPartition]); + }, [isAnimating, animationStep, committedPartition, baseHue]); - const renderFerrersDiagram = (partition: number[], highlightHook?: { row: number; col: number }) => { + const renderFerrersDiagram = (partition: number[], highlightHook?: { row: number; col: number }, isOriginal = true) => { if (partition.length === 0) return null; const boxSize = 30; @@ -112,18 +134,71 @@ const FerrersRogersRamanujan = () => { {partition.map((count, rowIdx) => (
{Array.from({ length: count }).map((_, colIdx) => { - const isHook = highlightHook && - ((rowIdx === highlightHook.row && colIdx >= highlightHook.col) || - (colIdx === highlightHook.col && rowIdx >= highlightHook.row)); + let backgroundColor = 'bg-secondary'; + let borderColor = 'border-border'; + let extraClasses = 'hover:bg-secondary/80'; + + if (isOriginal) { + // Original diagram: color completed hooks on diagonal + if (rowIdx === colIdx && rowIdx < hookColors.length) { + const color = hookColors[rowIdx]; + backgroundColor = ''; + borderColor = ''; + extraClasses = `scale-105 shadow-md`; + return ( +
+ ); + } + + // Highlight current hook being processed + const isHook = highlightHook && + ((rowIdx === highlightHook.row && colIdx >= highlightHook.col) || + (colIdx === highlightHook.col && rowIdx >= highlightHook.row)); + + if (isHook) { + backgroundColor = 'bg-primary'; + borderColor = 'border-primary'; + extraClasses = 'scale-110 shadow-lg'; + } + } return (
+ ); + })} +
+ ))} +
+ ); + }; + + const renderRRDiagram = (partition: number[]) => { + if (partition.length === 0) return null; + + return ( +
+ {partition.map((count, rowIdx) => ( +
+ {Array.from({ length: count }).map((_, colIdx) => { + const color = hookColors[rowIdx] || 'hsl(var(--secondary))'; + return ( +
); })} @@ -230,7 +305,7 @@ const FerrersRogersRamanujan = () => {

{rrPartition.join(" + ")} = {n} (parts differ by ≥ 2)

- {renderFerrersDiagram(rrPartition)} + {renderRRDiagram(rrPartition)}
)}