UNPKG

newton

Version:

A playful, particle-based physics engine designed from the ground up for JavaScript.

25 lines (20 loc) 995 B
p. Constraints are the third basic element of Newton and are its most powerful feature. p. They create rules that are applied to Particles after integration, like "All particles should stay within this rectangle," or "These two particles should be connected." p. BoxConstraint is a location constraint that keeps a particle within a rectangular area. Newton comes with a library of Constraints. pre.CodeBlock. var container = Newton.BoxConstraint(0, 0, 1000, 600); // x, y, width, height sim.add(container); p. The simulator runs constraints repeatedly to converge at an approximate solution. Since constraints can conflict with each other, it's a good idea to give Newton a hint about which constraints are most important. You can do this via the Simulator's <span class='Code'>solve</span> option: pre.CodeBlock. var sim = Newton.Simulator({ solve: [ Newton.PinConstraint, Newton.RopeConstraint ] // PinConstraint is more important than RopeConstraint });