Attractor (eg earth)
Attractee (eg satellite)
Gravity constant
Min/max that distance is clamped to.
const attractor = { position: { x:0.5, y:0.5 }, mass: 1 };
const attractee = { position: Points.random(), mass: 0.01 };
attractee = Forces.apply(attractee, Forces.computeAttractionForce(attractor, attractee, 0.005));
attractor = { position: { x:0.5, y:0.5 }, mass: 1 };
attractees = attractees.map(a => Forces.apply(a, Forces.computeAttractionForce(attractor, a, 0.005)));
// Create a force with all things as attractors.
const f = Forces.attractionForce(things, gravity);
// Apply force to all things.
// The function returned by attractionForce will automatically ignore self-attraction
things = things.map(a => Forces.apply(a, f));
attractor
thing attracting (eg, earth)
attractee
thing being attracted (eg. satellite)
gravity
will have to be tweaked to taste.
distanceRange
clamps the computed distance. This affects how tightly the particles will orbit and can also determine speed. By default it is 0.001-0.7
Computes the attraction force between two things. Value for
gravity
will depend on what range is used formass
. It's probably a good idea to keep mass to mean something relative - ie 1 is 'full' mass, and adjust thegravity
value until it behaves as you like. Keeping mass in 0..1 range makes it easier to apply to visual properties later.