An experiment with my Verlet Integration toy ( https://scratch.mit.edu/projects/443006411/ ) to make a chain. It had some... interesting results.
This project uses Verlet Integration (https://en.wikipedia.org/wiki/Verlet_integration) Verlet stores the current position and the previous one to calculate physics. This makes it easy to apply constraints, like keeping it in the screen, simply by changing the current position to be on-screen.