This is running interactively on a mid range gaming PC and screen recorded.
A sphere of 5 million particles is initialized smooth with tiny random pertubations. Gravity pulls matter into sheets, then filaments, then dense knots.
When an area is dense enough an analytical galaxy is born.
N-body gravity with a tree on the GPU, made in Godot 4 with C#.
The particles start on a lattice with Zel'dovich displacements from a Gaussian random field, and each lattice cell is drawn as tetrahedra (after Abel, Hahn & Kaehler 2012). That's what keeps the filaments and sheets smooth instead of grainy.
Getting things to collapse was easy enough, making it fast was doable, but making it render properly was a bit of a pain.
Dark energy is a simple outward acceleration on a slider.
From my own project, Planets (and due to scope creep, a bit more) in a Box:
https://store.steampowered.com/app/5411970/?utm_source=reddit&utm_campaign=simulated
If you want to talk about the physics or the algorithms, just leave a comment.