# 2d Procedural universe generation

I want to create a flat universe, where at first the whole universe is blank.

That would be represented by a parallax scrolling nebula background image.

What I want to do is represent the planets as disc shaped objects in the universe. They can be of various sizes.

The inside of the discs will consist of a landmass, then outside that will be a body of water and after that air.

what would be the best way to go about creating those tiles procedurally as for example the air would consist of various gases and the land of various minerals and resources.

My first thought is to create texture images and then stamp out the circles out of those textures, but problem is that those textures would have to wrap horizontal and vertically. Is there a fully procedural way of doing this?

-
Questions like this are better answered with some kind of visual to describe what you're after. The good answer below might be either too technical or not technical enough. – Richard Fabian Mar 23 '11 at 17:23

Procedural textures, particularly noise-based ones, can be made to tile. See this thread at GDNet for some discussion, as well as this journal entry. There's also this link, which sounds interesting although I can't speak for its veracity.

As for procedurally generating the world, there's this article written by the guy developing Infinity. His system is 3D but you could probably adapt the techniques easily enough.

There's a whole wiki on procedural content generation, too.

-
Pff. I need to learn to type faster. This is basically what I have in the editor window below... +1 to you Sir. – bummzack Mar 23 '11 at 15:35
cheers i'll give it a go. – Joseph Le Brech Mar 23 '11 at 18:30

It sounds to me like you want rectangular textures with air on top and dirt on the bottom. You can map rectangular textures to the circles by making the U texture coordinate represent angle around the circle, and V texture coordinate represent distance from the center of the circle. For larger planets, U can wrap around the planet several times.

To convert from regular 2D coordinates XY to the above UV coordinates, you can do math like so:

``````y -= planet_center.y;
x -= planet_center.x;
u = atan2( y, x );
v = sqrt( y*y + x*x );
``````

Care should be taken to avoid calculating this too close to the center of the planets...

-
I'm thinking more along the line of a vertical cross section of the universe like this i.imgur.com/gpCTc.jpg land, sea, air, void. etc.. – Joseph Le Brech Apr 19 '11 at 11:15
That's a reasonable way to partition space into types, but it will be a challenge to make it look like spherical planets. – bmcnett Apr 19 '11 at 18:03
theres no requirement to make it look too much like a planet. just enough random land, water, air in the right proportion and all on a hex grid along with other planets on that grid. – Joseph Le Brech Apr 19 '11 at 18:38
Ah then you will want to generate a lot of hexagonal texture tiles, with the constraint that the edge between land/air etc. show up in a predictable place between adjacent tiles? – bmcnett Apr 19 '11 at 19:20
yes, in a spherical manner. so the size of each layer (land, water..) is randomly picked and then in that land mass random land tiles will be placed for the planet, and the same for each layer. – Joseph Le Brech Apr 20 '11 at 17:00