Implementation Notes
- Delta Time Physics: All movement, turning, and animation phases are multiplied by `dt` (seconds per frame). This guarantees identical behavior across 60Hz, 144Hz, or lagging devices. `dt` is clamped to `0.1s` to prevent "physics explosions" if the browser tab is inactive.
- Autonomous Wandering: Each fish maintains a `wanderAngle` that drifts randomly. Steering is calculated by finding the shortest angular difference and applying a smooth turn capped by `maxTurnRate`, avoiding robotic linear paths.
- Boundary Interaction: Fish within a `margin` of the canvas edges receive a rotational force away from the wall. Position is subsequently clamped, creating a smooth "glide and turn" effect rather than hard bouncing.
- Rendering Optimization: Canvas transforms (`translate`, `rotate`) handle orientation efficiently. Tail wiggle uses a sine wave driven by `dt`. Background elements are drawn once per frame with minimal draw calls.
- Design Choices: Fish use HSL colors for vibrant, varied appearances. Constant speed was chosen over acceleration to maintain a calm, meditative aquarium aesthetic.