Build an Interactive Flocking Boids Physics Playground in HTML

A ready-to-use prompt that generates a self-contained HTML5 canvas boids simulation with real-time flocking sliders, cursor attract/scatter modes, and live telemetry.

The prompt

Prompt
Act as a senior creative technologist and front-end engineer. Build Starling Drift, an interactive nocturnal murmuration physics playground in a single self-contained HTML file. The simulation renders 120 autonomous boids on a full-bleed HTML5 canvas using cohesion, alignment, and separation steering forces. Include these exact features: 1. A floating glassmorphic control panel with real-time range sliders for Cohesion, Alignment, Separation, and Max Speed, plus a reset-to-defaults button. 2. Cursor interaction modes toggled via segmented buttons for Attract, Scatter, and Off, responding to both mouse and touch drag. 3. A live telemetry bar displaying active boid count, average flock speed, and frames per second. 4. Keyboard shortcuts: Space to pause or resume, R to scatter-reset positions, and M to cycle cursor mode. 5. Responsive layout fitting 360px to 1280px viewports with zero horizontal overflow, a deep midnight-slate palette with luminous cyan-to-amber directional boid chevrons, and prefers-reduced-motion support that shortens motion trails. Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.

Example output

One HTML file. Save it and open it in any browser.Open full screen
At a glanceWhat the boids playground lets you doControls and live feedback in the generated page
  1. Move or drag the cursorAttract or scatter the flock, or set Off
  2. Adjust the slidersCohesion, Alignment, Separation, Max Speed
  3. Watch the flock shiftFrom tight swirling ribbons to chaotic swarms
  4. Read the telemetry barLive speed and FPS

Example: Starling Drift, an interactive nocturnal murmuration physics playground. Move or drag your cursor across the canvas to attract or scatter the flock, or switch to Off for pure autonomous emergence. Adjust the Cohesion, Alignment, Separation, and Max Speed sliders in real time to watch the flock shift from tight swirling ribbons to chaotic swarms, while the telemetry bar tracks live speed and FPS.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Specifying the exact three steering forces and four sliders prevents vague physics and ensures immediate visual responsiveness.
  • Requiring an IIFE, inline styles, and zero external dependencies guarantees the simulation runs offline in any sandboxed preview.
  • Explicit keyboard shortcuts and prefers-reduced-motion rules bake in accessibility without extra prompting.

Paste the prompt into Gemini, ChatGPT, or Claude, then save the generated code as an .html file and open it in any browser—or preview it directly in Canvas or Artifacts.

Common edits

  • Add a predator boid that the flock actively flees from when enabled.
  • Include a color-theme toggle to switch between nocturnal cyan, bioluminescent green, and sunset amber.

Make it repeatable

Keep using this prompt without pasting it in every time.

Keep exploring

More in Animations & Effects