Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ineido/space
Doesn't do much. Just some bodies flying around in the void.
https://github.com/ineido/space
gravity nbody-gravity-simulation pygame
Last synced: about 1 month ago
JSON representation
Doesn't do much. Just some bodies flying around in the void.
- Host: GitHub
- URL: https://github.com/ineido/space
- Owner: INeido
- License: gpl-3.0
- Created: 2021-04-20T13:44:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-20T16:38:52.000Z (almost 2 years ago)
- Last Synced: 2023-03-06T01:13:37.472Z (almost 2 years ago)
- Topics: gravity, nbody-gravity-simulation, pygame
- Language: Python
- Homepage:
- Size: 27.3 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Space
Doesn't do much. Just some bodies flying around in the void.
## Settings
| Name | Description | Standard Value |
| ------ | ------ | ------ |
| FPS | Pretty self explanatory, isn't it? | 120 |
| drag | "Air"-Drag, but in space | 0.000001 |
| coll_loss | Loss of speed on collision | 0.000001 |
| res_x | Changes the screen width | 1920 |
| res_y | Do I have to tell you? | 1080 |
| zoom_factor | Zoooooooom | 0.98 |## Switches
| Name | Description |
| ------ | ------ |
| trace | Enables cool effect |
| edges | If enabled, bodies can't escape screen |
| gravity | The thing with the apple |
| collision_color | Bodies change colors on collision |## Controls
| Button | Description |
| ------ | ------ |
| ESC | Closes game |
| E | Resets bodies |
| S | Toggles between **Insert** and **Focus** mode |
| Left Click | Follows body when clicked (Focus) |
| A & D | Switch between bodies (Focus) |
| Left Click | Gravitational pull at cursor (Insert) |
| Right Click | Gravitational push at cursor (Insert) |
| Middle Click | Drag screen (Insert) |![](https://github.com/INeido/Space/blob/main/img/gif1.gif)
## Examples
Kinda stable orbit with 3 bodies
```
bodies.append(Body(p=(0, 300), v=(3, 0), r=5, c=white))
bodies.append(Body(p=(0 + 150, 200), v=(3, 0), r=5, c=white))
bodies.append(Body(p=(0, 0), r=75))
```Not really stable orbit with 2 bodies
```
bodies.append(Body(p=(100, - 100), v=(3, 2), r=25, c=white))
bodies.append(Body(p=(0, 0), r=50))
```2 bodies on collision course
```
bodies.append(Body(p=(-600, 0), r=50, v=(3, 0)))
bodies.append(Body(p=(600, 0), r=50, v=(-3, 0)))
```Create any amount of random bodies defined in **count**. (Don't recommend more than 50)
```
count = 10rand = random.choices(population=[["5"], ["10"], ["15"], ["20"], ["30"]],
weights=[0.35, 0.30, 0.20, 0.1, 0.05],
k=count)for x in range(count):
bodies.append(Body(p=(random.randint(-res_x / 2, res_x / 2),
random.randint(-res_y / 2, res_y / 2)),
v=(random.randint(-5, 5),
random.randint(-5, 5)),
r=int(int(''.join(rand[x]))),
c=white))
```You can paste these into the **reset** function.
![](https://github.com/INeido/Space/blob/main/img/gif2.gif)