SWAMP UI / COMPONENTS / FIREFLY CATCH

Firefly Catch

your cursor is a jar. sneak.

Move the jar slowly toward a firefly. They'll dodge once you're close — keep it on them for about half a second and they're caught. Fill the jar to 7 and a button appears: release them as a constellation. The meadow refills, the hunt continues.

No dependencies
Cursor-as-jar
Endless hunt
Constellation release
LIVE PREVIEW · MOVE THE JAR INSIDE THE MEADOW
drift the cursor in to begin
fireflies dodge if you rush
0/7
TOTAL CAUGHT
0
CONSTELLATIONS
0
IN MEADOW
0

When to use

A "don't disturb" widget: anywhere a user is supposed to slow down. The whole mechanic punishes rushing. Drop it in a "thank you" page after submission, a reading pause inside a long essay, a meditation app, or a slow homepage section.

Also: it makes a charming 404. The meadow is empty, the fireflies are not.

Skip to

1. HTML

The meadow, the jar (follows cursor), a HUD, fireflies injected by JS.

<div class="meadow" id="meadow"
     data-count="7"
     data-quota="7">
  <div class="jar" id="jar">...svg jar...</div>
  <div class="hud">...counter + release button...</div>
</div>

2. JavaScript — dodge & catch

Each firefly has a slow drift (sine + noise). On each frame: if jar is within ALERT px, push the firefly directly away from the jar; if it stays within CATCH px for CATCH_MS, it's caught.

// Swamp UI — Firefly Catch (dodge + catch loop)
const ALERT   = 90;   // px — distance at which they start dodging
const CATCH   = 22;   // px — distance that counts as "on top"
const CATCH_MS = 500; // must stay close this long

flies.forEach(f => {
  // natural drift
  f.vx += Math.cos(f.t) * 0.02;
  f.vy += Math.sin(f.t * 1.3) * 0.02;
  f.vx *= 0.92; f.vy *= 0.92;

  // dodge if jar is near
  const dx = f.x - jar.x, dy = f.y - jar.y;
  const d  = Math.hypot(dx, dy);
  if (d < ALERT) {
    const push = (ALERT - d) / ALERT * 0.9;
    f.vx += (dx / d) * push;
    f.vy += (dy / d) * push;
    f.el.classList.add('alert');
  } else f.el.classList.remove('alert');

  // catch timer
  if (d < CATCH) f.held += 16; else f.held = Math.max(0, f.held - 8);
  if (f.held >= CATCH_MS) capture(f);

  f.x += f.vx; f.y += f.vy;
  f.t += 0.04;
  bounce(f);
  draw(f);
});

3. Parameters you can tweak

WhereDefaultEffect
HTML data-count7How many fireflies live in the meadow at once.
HTML data-quota7How many you need before the RELEASE button appears.
JS ALERT90 pxDodge radius. Lower = harder to scare. Higher = jumpier.
JS CATCH22 pxHow close the jar must be. Lower = harder.
JS CATCH_MS500How long you must hold them. Higher = more patient game.

Released a constellation?

Feed the cats. Tip the lantern-keeper.

🧋 TREAT THE SWAMP →
More in the garden → Firefly Cursor, Firefly Tour, Lure Cast, Swamp Tarot, Lily Pad Stepping.
Browse all →