Limit hooks to main diagonal

Restrict Ferrers-Rogers-Ramanujan animation to traverse only the main diagonal (top-left to bottom-right) of the Ferrers diagram. Process hooks at positions (i, i) as long as a box exists, stopping when the diagonal ends. This replaces the previous diagonal traversal to avoid generating excessive hooks.

X-Lovable-Edit-ID: edt-dd8be332-f1e2-49f5-9077-6354075ccfe7
This commit is contained in:
gpt-engineer-app[bot] 2025-12-01 07:06:42 +00:00
commit 9433f41cbf

View file

@ -58,49 +58,31 @@ const FerrersRogersRamanujan = () => {
setIsAnimating(true); setIsAnimating(true);
}; };
// Animation effect // Animation effect - traverse main diagonal only
useEffect(() => { useEffect(() => {
if (!isAnimating || committedPartition.length === 0) return; if (!isAnimating || committedPartition.length === 0) return;
const partition = committedPartition; const partition = committedPartition;
// Find the hook at current animation step // Main diagonal: positions (0,0), (1,1), (2,2), ... while box exists
let found = false; const row = animationStep;
let hookCount = 0; const col = animationStep;
let targetRow = 0, targetCol = 0;
const maxRow = partition.length; // Check if this diagonal position has a box
const maxCol = partition[0] || 0; if (row >= partition.length || col >= partition[row]) {
// Animation complete - no more diagonal boxes
for (let d = 0; d < maxRow + maxCol && !found; d++) {
for (let r = 0; r <= d; r++) {
const c = d - r;
if (r < partition.length && c < partition[r]) {
if (hookCount === animationStep) {
targetRow = r;
targetCol = c;
found = true;
break;
}
hookCount++;
}
}
}
if (!found) {
// Animation complete
setIsAnimating(false); setIsAnimating(false);
setAnimatingHook(null); setAnimatingHook(null);
return; return;
} }
setAnimatingHook({ row: targetRow, col: targetCol }); setAnimatingHook({ row, col });
// Calculate hook size // Calculate hook size: boxes to the right + boxes below + 1 (the box itself)
const boxesRight = partition[targetRow] - targetCol - 1; const boxesRight = partition[row] - col - 1;
let boxesBelow = 0; let boxesBelow = 0;
for (let r = targetRow + 1; r < partition.length; r++) { for (let r = row + 1; r < partition.length; r++) {
if (partition[r] > targetCol) { if (partition[r] > col) {
boxesBelow++; boxesBelow++;
} else { } else {
break; break;