BALL IN CONCAVE SQUARE · 1024×1024 TORUS

Both bodies have mass 1. The ball reflects off the inner walls of the moving hole as a 1-D elastic collision (equal masses → the touching velocity component is exchanged), so total momentum and kinetic energy are conserved exactly — no friction, no loss. The field wraps in X and Y; the square and ball are drawn as tiled copies and all relative math uses the shortest toroidal distance.