The Nature of Code by Daniel Shiffman is an excellent entry point - it teaches fundamentals of physics simulations with clear examples in Processing/p5.js.