diff --git a/README.md b/README.md new file mode 100644 index 0000000..031dc5d --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Simple Gravity Simulator in Python + +This is a simple gravity simulator written in Python. It uses the Tkinter library to display the simulation and the Universal Gravitation formula to calculate the forces between the objects. + +## How to use + +- add or remove objects by modifying the code in `main.py` +- `python main.py` to run the simulation +- you can accelerate the simulation with the first slider +- you can change the scale of the simulation with the second slider +- you can change the frame rate of the simulation with the third slider + +## Example + +![example](./images/example.gif) \ No newline at end of file diff --git a/images/example.gif b/images/example.gif new file mode 100644 index 0000000..56f9340 Binary files /dev/null and b/images/example.gif differ diff --git a/main.py b/main.py index d28f805..41c9a2c 100644 --- a/main.py +++ b/main.py @@ -70,6 +70,11 @@ class Planet: n_x = vec_y * -1 n_y = vec_x * 1 + n_len = sqrt(n_x ** 2 + n_y ** 2) + + n_x /= n_len + n_y /= n_len + self.set_initial_velocity(n_x * v, n_y * v) class System(): @@ -95,6 +100,7 @@ class System(): def main(): window = Tk() + window.title("Simple Grav Sim") canvas = Canvas(window, bg="black", width=WIDTH, height=HEIGHT) canvas.pack()