N-Body Simulation banner

N-Body Simulation

6 devlogs
51h 11m 25s

This is a very simple n body simulation I’m working on in love2d so i can learn the framework and try and understand some of the equations I’ve learned at school. It supports euler and verlet integration..

This project uses AI

Used ChatGPT to format the README

Demo Repository

Loading README...

proudfridge

Shipped this project!

Hours: 51.19
Cookies: 🍪 1106
Multiplier: 21.61 cookies/hr

It’s finally done! I would have loved to add a few extra features, like a proper 3D perspective camera and the ability to download planetary data from the NASA Horizons API, but with exams coming up, I won’t have the time to squeeze them in before Flavortown end.

All in all, I built a simple N-Body simulator that supports Euler and Verlet integration, with a Solar System preset. The most challenging part was implementing the 3D camera. Love2D is designed for 2D games, so getting all the math right to make a 2D framework display a (kind of) convincing 3D simulation took a lot of work.

I’m especially proud of the UI. Thanks to the nuklear-love library, it was easy to implement but made the project look much cleaner and more polished.

This was a lot of fun! I still plan to continue working on this project after my exams and the Flavortown event ends. There’s still plenty of room for improvements, and it’s far from perfect.

proudfridge

There’s UI now!

The simulation now has a main menu and a proper information panel, implemented using the love-nuklear library. In addition, you can now press “r” to toggle the rendering of the planets’ names.

Through the main menu, the user can now specify:

  • The timestep of the simulation
  • The amount of time to simulate the system for
  • Which integrator to use for the simulation
    As usual, here’s a short video showcasing the new UI:
0
proudfridge

Hello again!

2 month have passed! And i kind of forgot about this project…

For this update, i wasted a lot of time trying to write a plot class, which i scrapped in the end. The only (substantial) addition i have to show is 3D rendering (without perspective). There’s still some kinks to iron out (like objects appearing in front of other objects when they’re supposed to be behind), but for now, it just makes the simulation looks nicer in general. As usual, I’ve added clips of the new rendering system (with 500 planets). I’ll see you in a few days when I’ve added something useful to the project.

0
proudfridge

It’s been a while!

I’ve added few things during the last weeks:

Changes:

  • Added verlet integration, you can switch between integrators by pressing ‘i’
  • Added an indicator at the top of the screen that show which integrator the simulation is currently using
  • Added the option to spawn new planets that orbit the sun instead of being stationary (As shown in the GIF below)
  • The simulation is now computed in 3D instead of 2D (mathematically, not graphically, but it would be nice if I add that later)
  • Added a very crude debug menu to the left
  • Updated the solar system’s planets positions and velocities
  • Added the Moon

Here’s a video showing the new spawning function in action with 500 planets or so.

0
proudfridge

Turns out the simulation wasn’t implemented properly, so that’s fixed. On another note, I’ve added a working camera system! You can now move the camera by using wasd and zoom in/out by pressing the up and down arrows respectively. Additionally, you fix the camera’s position on a planet by pressing “x” and switch the current planet you’re fixed on pressing “n” .

Here’s some other small changes I’ve made to this project:

  • Planets now have a trail behind them that can be enabled/disabled by pressing “t”
  • The button to show the debug lines has been changed to “1”

And that’s everything I’ve added for now, which, i do admit, is very little for almost 10 hours of work, but now that I’ve gotten familiarized with the love2d framework, i hope i can pick up the pace a little bit.

I’ve attached an image showing the solar system simulated in this program as a proof of concept. As you can see, is somewhat inaccurate because I mistyped the some of the planets’ initial velocities and never bothered to fix them.

Attachment
0
proudfridge

Currently, you can spawn new planets with “w”, clear all spawned planets with “c”, pause the simulation with space and show the debug lines by pressing “e”. Hopefully I’ll remember to write all of this in the readme file

Attachment
0