A rectangle with draggable corner handles contains an autonomous snake with a fixed body length. Drag a corner inward and the walls press the entire body flat — the tail piles against the boundary as the chain tries to stay intact.
The head steers away from its own body to avoid self-crossing. The body uses constraint relaxation: each frame runs three passes of chain-follow and box-clamp, so the walls act as hard boundaries for every segment, not just the head. A final separation pass pushes any overlapping non-adjacent segments apart, tail-side first.
// controls