From 8faa4df49e420bb781cd1d7961b7f913e845bfe8 Mon Sep 17 00:00:00 2001 From: johnruina Date: Tue, 16 Jun 2026 09:50:25 -0400 Subject: [PATCH] fluid fixes --- fluid.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fluid.html b/fluid.html index e9010f7..3469799 100644 --- a/fluid.html +++ b/fluid.html @@ -399,6 +399,9 @@ let isDown = false; let running = true; let animId = null; + let idleFrames = 0; + const AUTO_BURST_INTERVAL = 600; + const IDLE_RESET_FRAMES = 120; function canvasCoords(e) { const rect = canvas.getBoundingClientRect(); @@ -686,6 +689,7 @@ if (keyState['d']) fluidPanX -= 0.01 / fluidZoom; if (isDown && prevMouseX >= 0) { + idleFrames = 0; const mx = (mouseX - canvas.width / 2) / canvas.width / fluidZoom + fluidPanX + 0.5; const my = (mouseY - canvas.height / 2) / canvas.height / fluidZoom + fluidPanY + 0.5; const pmx = (prevMouseX - canvas.width / 2) / canvas.width / fluidZoom + fluidPanX + 0.5; @@ -693,6 +697,15 @@ const dx = mx - pmx; const dy = my - pmy; addForce(dx * 3, dy * 3, mx, my, 0.04 / fluidZoom); + } else { + idleFrames++; + if (idleFrames > IDLE_RESET_FRAMES && idleFrames % AUTO_BURST_INTERVAL === 0) { + let totalDye = 0; + for (let i = 0; i < d.length; i++) totalDye += d[i]; + if (totalDye < 1) { + burstCenter(); + } + } } step(); @@ -719,6 +732,7 @@ mouseX = p.x; mouseY = p.y; prevMouseX = mouseX; prevMouseY = mouseY; isDown = true; + idleFrames = 0; } function mouseMove(e) { @@ -743,6 +757,7 @@ mouseX = p.x; mouseY = p.y; prevMouseX = mouseX; prevMouseY = mouseY; isDown = true; + idleFrames = 0; } function touchMove(e) { @@ -770,6 +785,7 @@ document.addEventListener('keydown', (e) => { if (e.key === 'Escape') window.location.href = 'index.html'; + if (e.key.toLowerCase() === 'r') { resetFluid(); idleFrames = 0; } }); window.addEventListener('resize', resizeFluid);