Star map generation

Non-platform specific questions.

Star map generation

Postby Leif » Thu Oct 20, 2011 10:14 am

Guys, another question

I'm making an algorythm of starmap creation

Code: Select all
for (i=0;i<5; i++)
for (j=0;j<3; j++)
CreateActor("p_Large_star", "1", "(none)", "(none)",
                                  30+i*160+rand(160-i*10)-width/2,
                                  30+j*160+rand(160-j*10)-height/2, true);


In this example I split screen (800x480) onto 15 squares 160x160. ( dimensions just for current example)

Result is
StarMap.png

I'm not satisfied with it. Map often looks like plain field of evenly placed stars and easily can visually divided on squares. Often stars stay very close to each other.

What is needed? Something like this
orion map.jpg


- unevenly placed stars ;
- quantity of stars 16-18;
- minimal distance between stars =50;
- maximum distance from any one star to closest star =250;

Any Ideas ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Star map generation

Postby Fuzzy » Thu Oct 20, 2011 2:31 pm

Yup. I once had that very problem when I was simulating random icicles.

Lets say you have an x distance of 800. You'll decide on an x density for stars, and make a variable for that. Actually, lets use a #define. We might as well define a y density too, and matching offsets.

Code: Select all
// in global code
int density_divisor = 8;
#define X_DENSITY view_width / density_divisor
#define Y_DENSITY view_height / density_divisor
// fancy division by 2 trick.. it always rounds to an integer
// 8 >> 1 is 4.
#define max_offset = density_divisor >> 1


We are going to be limited to a max of 8 in a row, and 8 in a column, but we wont always have 64 stars. Our max_offset is always smaller than our spacing determined by ?_DENSITY. This means we shouldnt have overlaps. By controlling max_offset, we can keep stars from being too close.

Code: Select all
void placeStars() {
    int randchance = 0;
    int x_star_offset, y_star_offset;
    for(i=0;i<X_DENSITY; i++) {
        // we give each column chances to have stars. We dont actually place one yet.
        for(j=0;j<Y_DENSITY;j++) {
            if (randomStarHere() == 1) { // 50% chance? 1 in 5000? Only you and the function know...
                x_star_offset = rand(0, max_offset); // offset from the grid...
                y_star_offset = rand(0, max_offset); // but not enough to overlap the next
                CreateActor("p_Large_star", "1", "(none)", "(none)", i*X_DENSITY+x_star_offset, j*Y_DENSITY+y_star_offset, true);
            }
        }
    }
}


Unfortunately I cannot test it, but it should give you an idea. By controlling densities and max offsets, you can influence how the stars arrange themselves. If max offset is too small (or density is high), you will see stars arranged in a rough grid. Its random, but its a controlled random.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Star map generation

Postby DST » Fri Oct 21, 2011 12:34 am

Not sure what you planned to do with this starmap, but a couple of suggestions:

Use a few stars and draw_from on a canvas to increase the amount of unique star types (by changing the scale of drawing) for a single background image, drawn once. The canvas at that point just becomes a huge graphic (not much overhead). You can use multiple canvases for different star layers, and if stars are 'selectable' as with space sim types, just keep those selectable stars as the actual actor star objects. The canvas is just a background starfield decoration.

Another idea is to create star cluster points. Start with 5 or so random points on the field of view; make a loop for each one to spawn stars in random distances around those clusters, in addition to what you're already drawing. Clusters of dense stars are more convincing than a random mesh of stars (at least in traditional art).
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest