Galaxy generation

from Red Blob Games
20 Mar 2018

Idea: generate a galaxy full of star systems, with connections between them. Stars should be closer together, and have more connections, near the center of the galaxy.

Density of {{points.length}} stars

The stars are generated uniformly and then stretched by setting the radius (0.0–1.0) to radius{{stretch}}. This pushes points close to the center closer together and points near the rim farther apart. Idea from Rob Shillingsburg. I haven’t yet tried putting in Poisson Disc blue noise points but this jittered grid seemed good enough for a demo (and so easy to code).

Connections between stars

The main algorithm is Delaunay Triangulation. It will connect all the stars together with non-overlapping edges. Then I’m going to remove some of those edges.

I build two sets of connections. The required connections are chosen by running a random walk from the center. I always keep those connections, to ensure everything is reachable. We don’t want disconnected “islands” of stars that can’t be reached from the galactic center. The required connections alone are a bit too sparse. The optional connections are kept when distance_from_center < random(). That way near the center they’re almost always kept and near the rim they’re almost never kept. It makes the center stars feel more connected and the rim stars feel more remote.

There are some issues around the rim of the galaxy. I have some ideas of how to solve them but I haven’t implemented them yet.

Email me at , or tweet to @redblobgames, or post a public comment: