commit
This commit is contained in:
parent
40871f7cd5
commit
ab87078b21
3 changed files with 21 additions and 0 deletions
15
README.md
Normal file
15
README.md
Normal file
|
@ -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
|
||||
|
||||

|
BIN
images/example.gif
Normal file
BIN
images/example.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
6
main.py
6
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue