fluid fixes
This commit is contained in:
+16
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user