A basic three-body simulation written in Rust. Used macroquad for graphics.
Each Body struct is initialized with position, velocity, acceleration, mass, and force (there are some other values but those are not as relevant).
On each update, the force between two bodies is calculated with Newton's Universal Law of Gravitation:
$$F = G \frac{m_1 m_2}{r^2}$$
Since this is a 2-dimensional simulation, the resultant force $F$ is multiplied by the $\Delta x$ and $\Delta y$ to get the $x$ and $y$ components of the force respectively.
Each force acting on the body should be summed:
$$F_{total} = \sum_{j \neq i} F$$
Then, $F=ma$ is used to solve for $a$ or accelration. Rewriting the equation: $a = \frac{F}{m}$
From there, basic kinematics equations use dt or $\Delta t$ to solve for an updated velocity component and position component:
$$v = v_i + at$$
$$p = p_i + vt$$
I recently watched the 3 Body Problem show.