I played with a simple program like that for the Amiga when I was younger, and then I discovered that there was an O(n log n) algorithm[1] rather than the obvious O(n^2) one. Never was up to writing a program to use it.
I highly recommend Space Engine
https://store.steampowered.com/app/314650/SpaceEngine/
This is the best web-based equivalent i found with a quick search:
https://hermann.is/gravity/
And this is a rather fine tutorial on writing your own:
https://css-tricks.com/creating-your-own-gravity-and-space-s...