Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

very basically like this

let dt = 0.01;                 // stepsize
let t0 = random(0, TWO_PI);    // random starting angle
let r;                         // star-positions in polar coordinates
let t;                         // as in:  r * exp(t)
let x0 = width/2;              // center of the galaxy
let y0 = height/2;
let scale = 40;                // bigger numbers draw a bigger galaxy
let numberOfStars = 1000;      // stars in one arm of the galaxy
// draw one spiral arm
for (let i = 0; i < numberOfStars; i++) {
    // calculate polar coordinates of the next star to draw
    t = t0 + i * dt;
    let r = (t - t0) * scale;
    
    let x = x0 + r * cos(t);    // convert to cartesian coordinates
    let y = y0 + r * sin(t);    
    
    let starRadius = 10;
    DrawCircleAt(x, y, starRadius);
}
And then I have a for loop or whatever around this codeblock to draw as many spiral arms as I want.
I also add some random noise to pretty much every calculation, just to make things seem a little more organic.

You can also squish the galaxy by deciding on some squishX and squishY factors before drawing any arms and then in your cartesian coordinate conversion you have
let x = x0 + (r/xSquish) * cos(t);
let y = y0 + (r/ySquish) * sin(t);
To make it more colorful, I pick a starting color and every time after I draw a star, I slightly change the color - I do the same after every spiral arm.

Hope that helps and thank you for checking it out and commenting:)

That was what I think of, cause that doesn't looks like a copy/paste bitmaps at all, way too organic. More galaxies types and/or variety would be great imo. Also you can easily pump that color randomization up, by generating a simple color palette to constraint color value, that cost nothing.

I planned for different types of galaxies, but most of the time was spent on the generator when you zoom one level in from the planets.