For each object in the project, I created a separate class that contained functions for determining gravity, drawing, and updating velocity and position.
In my project I defined it using this formula:
G ⏤ Gravitational constant
m ⏤ mass
r ⏤ distance between object1 and object2
This formula returns only the force modulus
To get a vector for x and y I use the arctan function - the opposite of tan with the values Δx, Δy
Δx ⏤ x2 - x1
Δy ⏤ y2 - y1
Next, I use cosine and sine to determine the horizontal (x) and vertical (y) respectively, multiplying them by force
To update the velocity and positions, I used Euler's method and Newton's second law:
Where:
v ⏤ velocity
a ⏤ acceleration
x ⏤ position x
y ⏤ position y
Δt ⏤ delta time (in my case it's TIMESTEP)
Newton's second law for finding acceleration:

Where:
F ⏤ force
m ⏤ mass
This is a common method for drawing objects in pygame but using SCALE to make the object fit on the screen.
This program can draw a circular object of any color, any radius, any position (x, y), and any mass.
This is what it looks like in the example:
WIDTH / 2, HEIGHT / 2 ⏤ x, y cordinate
30 ⏤ radius
pg.Color('Yellow') ⏤ color
1.989e30 ⏤ mass
This is just a simulation of orbital motion. Can be used as a toy


