No.191 · Backgrounds
Firefly Sync
A meadow at dusk where fireflies flash on their own clocks and nudge them toward the flashes they can see, so over half a minute scattered blinks become waves of light rolling through the grass. The pointer is a lantern: fireflies near it lose the beat and drift to its glow.
The prompt
Written for the variant you picked above: Dusk
Build a canvas 2D dusk meadow with fireflies that synchronise like real ones. Scene: sky gradient, a few stars and two noise-shaped ridges are drawn once per size into an offscreen canvas; every frame draws that, then the far fireflies, then a field of grass blades (one filled path of quadratic blades, ~1 per 3px, swaying with a sine plus noise), a lantern glow if active, then the near fireflies — so some sit behind the grass and some in front. Fireflies (~0.9 per 10,000 px², 36–130): each wanders on a slow noise field over the lower half, has a depth z (size and brightness) and a phase oscillator with its own frequency (period 1.3–1.6s). Brightness is a brief Gaussian flash around phase 0 (σ 0.32 rad) over a faint ember, drawn additively with a pre-tinted Gaussian glow sprite (stops e^(−4.4r²)(1 − r⁴), so no edges) plus a tiny bright core during the flash. Synchrony (Kuramoto): dθᵢ/dt = ωᵢ + K · Σⱼ wᵢⱼ sin(θⱼ − θᵢ) / Σⱼ wᵢⱼ over neighbours within R = max(160px, 28% of the width), with wᵢⱼ = 1 − d²/R². K ramps from 0 to 2.4 over the first 25s, so you watch scattered blinking turn into rolling waves and then a field that pulses together. Expose the order parameter r = |Σ e^{iθ}| / N via an onSync callback twice a second (the demo shows "In step · 74%"). The pointer is a lantern: a warm soft light (and a small bright core) that fades in; fireflies within ~150px (Gaussian) get jitter added to their clocks, so they fall out of step, and drift toward the light; they resynchronise after it leaves. One rAF loop, paused offscreen and in hidden tabs; ~33fps and 70% of the fireflies on touch. Reduced motion: simulate 12s up front and draw one still, synchronised frame. Selected variant — Dusk (dusk): theme="dusk": a violet sky warming to a low amber horizon, a few stars. This selection takes precedence over references to other themes or options in the general brief. Implement this selected appearance; do not add a variant picker or alternative appearances unless requested. Implementation requirements: Use React and TypeScript. Keep the component self-contained, with uniquely scoped CSS and no animation libraries. Include required imports, styles and font setup in the result. Interaction: Move over the meadow: your lantern scatters the rhythm nearby and draws fireflies in. Motion: Continuous while visible; synchrony builds over ~25s; flashes ~1.5s apart. Accessibility: The canvas is aria-hidden and decorative; overlay text sits above it. Reduced motion draws one still frame. Responsive behavior: Firefly count, grass and ridges are rebuilt for the new size on resize. Touch: Touch drag carries the lantern; it fades when the finger lifts. 70% of the fireflies at ~33fps. Preserve keyboard access, visible focus and reduced-motion behavior. Keep fictional demo data and simulated service calls in a separate usage example; expose callbacks for real actions and recover from rejected requests. Keep usage-example links inside the demo: use local buttons or prevent navigation. Demonstration links must not navigate to Vitrine routes or open other pages; preserve real URL support in the reusable component itself. Verify the result at narrow and wide viewport sizes, with keyboard input and reduced motion enabled.
Notes
- Interaction
- Move over the meadow: your lantern scatters the rhythm nearby and draws fireflies in.
- Motion
- Continuous while visible; synchrony builds over ~25s; flashes ~1.5s apart.
- Accessibility
- The canvas is aria-hidden and decorative; overlay text sits above it. Reduced motion draws one still frame.
- Responsive
- Firefly count, grass and ridges are rebuilt for the new size on resize.
- On touch
- Touch drag carries the lantern; it fades when the finger lifts. 70% of the fireflies at ~33fps.