Generating terrain radially

So I’ve been spending a few hours now looking for an algorithm to help me radially generate terrain. All I’ve been able to find is articles of people asking how to generate terrain like in Terraria, however, that’s not what I’m after

Specifically I’m going to use this to random generate asteroids of various sizes, with various minerals and such. From looking at the above mentioned articles, I’ve been able create Terraria like terrain using the following code. Which is a slightly modified version of the popular tutorial found here

GameObject Stone = (GameObject)Resources.Load("Stone");
        GameObject Grass = (GameObject)Resources.Load("Grass");
        byte[,] blocks = new byte[x, y];

        for (int px = 0; px < blocks.GetLength(0); px++)
        {
            int stone = NoiseGenerator.Noise(px, 0, 20, 20, 1);
            stone += NoiseGenerator.Noise(px, 0, 50, 30, 1);
            stone += NoiseGenerator.Noise(px, 0, 10, 10, 1);
            stone += 25;

            int grass = NoiseGenerator.Noise(px, 0, 100, 35, 1);
            grass += NoiseGenerator.Noise(px, 0, 50, 30, 1);
            grass += 25;

            for (int py = 0; py < blocks.GetLength(1); py++)
            {

                if (NoiseGenerator.Noise(px, py, 12, 16, 1) > 10)
                {
                    Instantiate(Grass, new Vector3(px, py), Quaternion.identity);
                }
                else if (py < stone && py > -stone /*&& NoiseGenerator.Noise(px, py*2, 16, 14, 1) < 10*/)
	            {
                    Instantiate(Stone, new Vector3(px, py), Quaternion.identity);
	            }
                else if (py < grass && py > -grass/*&& NoiseGenerator.Noise(px, py * 2, 16, 14, 1) < 10*/)
                {
                    Instantiate(Grass, new Vector3(px, py), Quaternion.identity);
                }                
            }
        }

What I can’t for the life of me wrap my head around, is how would one modify this to create an asteroid-like shape.

Thanks in advance :slight_smile:

I suppose one way of generating random asteroid shapes would be to create a map and repeatedly draw random circles to it:

  1. Create a 2d integer array the size of your asteroid. Zeroes will be empty space, Ones will be filled with tiles.
  2. Get a random number of circles.
  3. Calculate the maximum radius for a circle to fit in the array.
  4. For each circle:
    5. Calculate a random radius up to the max radius
    5. Calculate a random position such that a circle of given radius will fit in the array.
    6. “Draw” the circle to the 2d array (for each pixel of the circle, set a 1 to the array), looks like this should work: c - fast algorithm for drawing filled circles? - Stack Overflow
  5. You should now have a 2d array of 1s and 0s marking the shape of your asteroid. You can use this as a lookup table in your tile generation to see if a tile should be created or not.