updated site and images

This commit is contained in:
2026-08-22 20:18:50 -07:00
parent 1b4db70930
commit 2291e2d13f
9 changed files with 134 additions and 118 deletions

View File

@@ -13,14 +13,12 @@ const DIFFUSION_ITERATIONS = 2;
const PROJECT_ITERATIONS = 3;
const VELOCITY_DAMP = 0.1;
const DYE_DAMP = 0.1;
const TRAIL_LIFETIME_MS = 184;
const TRAIL_LIFETIME_MS = 2000;
const TRAIL_RADIUS_PX = 100;
const TRAIL_EASE = 2.5;
const TRAIL_STRENGTH = 3;
const TRAIL_FORCE_DECAY = 1.2;
const TRAIL_WOBBLE = 0.14;
const DRAG_THRESHOLD_PX = 12;
const MAX_TRAIL_POINTS = 24;
export function initFluidByteField(canvasId) {
const canvas = document.getElementById(canvasId);
@@ -57,11 +55,6 @@ export function initFluidByteField(canvasId) {
let accumulator = 0;
let running = true;
const trails = [];
let dragStartX = 0;
let dragStartY = 0;
let dragging = false;
function resize() {
const rect = container.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 2);
@@ -111,8 +104,16 @@ export function initFluidByteField(canvasId) {
function onPointerMove(e) {
const rect = container.getBoundingClientRect();
const px = e.clientX - rect.left;
const py = e.clientY - rect.top;
let px, py;
if (e.touches && e.touches.length > 0) {
px = e.touches[0].clientX - rect.left;
py = e.touches[0].clientY - rect.top;
} else {
px = e.clientX - rect.left;
py = e.clientY - rect.top;
}
if (cols > 0 && lastPointerX > -9000 && px >= 0 && py >= 0 && px <= rect.width && py <= rect.height) {
const elapsed = Math.min(0.05, Math.max(0.001, (e.timeStamp - lastPointerTime) / 1000));
const fx = (px - lastPointerX) / CELL_SIZE / elapsed * ADVECT_SCALE;
@@ -129,78 +130,7 @@ export function initFluidByteField(canvasId) {
lastPointerY = -9999;
}
function onPointerDown(e) {
const rect = container.getBoundingClientRect();
const px = e.clientX - rect.left;
const py = e.clientY - rect.top;
dragStartX = px;
dragStartY = py;
dragging = px >= 0 && py >= 0 && px <= rect.width && py <= rect.height;
}
function onPointerUp(e) {
if (!dragging) return;
dragging = false;
const rect = container.getBoundingClientRect();
const px = e.clientX - rect.left;
const py = e.clientY - rect.top;
if (Math.hypot(px - dragStartX, py - dragStartY) > DRAG_THRESHOLD_PX) return;
trails.push({ x: px, y: py, age: 0, seed: Math.random() * Math.PI * 2 });
if (trails.length > MAX_TRAIL_POINTS) trails.shift();
}
function applyTrails() {
if (!trails.length) return;
const lifetimeSec = TRAIL_LIFETIME_MS / 1000;
const cellsPerRadius = TRAIL_RADIUS_PX / CELL_SIZE;
for (let i = trails.length - 1; i >= 0; i--) {
const trail = trails[i];
trail.age += DT;
const progress = trail.age / lifetimeSec;
if (progress >= 1) {
trails.splice(i, 1);
continue;
}
const eased = 1 - Math.pow(1 - progress, TRAIL_EASE);
const ringRadius = eased * TRAIL_RADIUS_PX / CELL_SIZE;
const remaining = 1 - progress;
const intensity = 0.35 + 0.65 * eased;
const force = TRAIL_STRENGTH * Math.pow(remaining, TRAIL_FORCE_DECAY);
const dyeAmount = 0.2 * Math.pow(remaining, 2);
const cx = trail.x / CELL_SIZE;
const cy = trail.y / CELL_SIZE;
const seed = trail.seed;
const band = ringRadius * 1.3 + cellsPerRadius;
const xMin = Math.max(1, Math.floor(cx - band));
const xMax = Math.min(cols - 2, Math.ceil(cx + band));
const yMin = Math.max(1, Math.floor(cy - band));
const yMax = Math.min(rows - 2, Math.ceil(cy + band));
for (let y = yMin; y <= yMax; y++) {
for (let x = xMin; x <= xMax; x++) {
const dx = x - cx;
const dy = y - cy;
const dist = Math.sqrt(dx * dx + dy * dy);
const angle = Math.atan2(dy, dx);
const wobble = 0.5 * Math.sin(6 * angle + seed) + 0.25 * Math.sin(3 * angle + 0.05 * dist + 0.3 * seed) + 0.5;
const wobbleAmount = TRAIL_WOBBLE * (2 * wobble - 1) * intensity;
const targetRadius = ringRadius * Math.min(1.6, Math.max(0.6, 1 + wobbleAmount));
const ringDist = Math.abs(dist - targetRadius) / cellsPerRadius;
if (ringDist >= 1) continue;
const falloff = smoothstep(1 - ringDist);
const forceMul = Math.min(2.2, Math.max(0.4, 1 + wobbleAmount));
const invDist = dist > 0.001 ? 1 / dist : 0;
const idx = x + y * cols;
velX[idx] += dx * invDist * force * forceMul * falloff;
velY[idx] += dy * invDist * force * forceMul * falloff;
dye[idx] = Math.min(1.5, dye[idx] + dyeAmount * forceMul * falloff);
if (Math.random() < 0.03 * falloff) glyphs[idx] = Math.floor(Math.random() * 256);
}
}
}
}
function step() {
applyTrails();
const visc = 1.5 * DT;
velX0.set(velX);
diffuse(velX, velX0, visc, cols, rows, DT, DIFFUSION_ITERATIONS);
@@ -255,18 +185,18 @@ export function initFluidByteField(canvasId) {
videoLuminance = (r * 0.299 + g * 0.587 + b * 0.114) / 255;
}
const baseAlpha = 0.04 + videoLuminance * 0.22;
const baseAlpha = 0;
if (d <= 0.02) {
ctx.shadowBlur = 0;
ctx.globalAlpha = baseAlpha;
ctx.fillStyle = 'rgba(0, 0, 0, 0.45)';
ctx.fillStyle = 'rgba(255, 255, 255)';
ctx.fillText(hex, x * CELL_SIZE + half, y * CELL_SIZE + half);
} else {
const alpha = d * FADE_RATE;
const activeAlpha = Math.min(alpha + baseAlpha, MAX_ALPHA);
const alpha = d * 1.5;
const activeAlpha = Math.min(alpha + baseAlpha, 1.0);
ctx.globalAlpha = activeAlpha;
ctx.fillStyle = '#ffffff';
ctx.shadowColor = '#ffffff';
ctx.shadowBlur = 0;
ctx.fillText(hex, x * CELL_SIZE + half, y * CELL_SIZE + half);
}
}
@@ -304,8 +234,8 @@ export function initFluidByteField(canvasId) {
new ResizeObserver(resize).observe(container);
window.addEventListener('pointermove', onPointerMove, { passive: true });
window.addEventListener('pointerleave', onPointerLeave);
window.addEventListener('pointerdown', onPointerDown, { passive: true });
window.addEventListener('pointerup', onPointerUp, { passive: true });
window.addEventListener('touchmove', onPointerMove, { passive: true });
window.addEventListener('touchend', onPointerLeave);
document.addEventListener('visibilitychange', onVisibilityChange);
resize();