Subject: REND386 starfield generator

From: Bernie Roehl <broehl>
Date: Mon, 9 Nov 92 16:45:46 EST

For those who may be working on non-terrestrial scenes for rend386,
I've written a very simple star field generator (included below).

While star fields don't really look like this (all the stars are very far
away, and you'd never have the sensation of passing "among" them), it's
an effect used quite often in science fiction films and television programs.
Besides, it took all of five minutes to write and test.

Usage is simple:

        plgstars [-c] n >stars.plg

The n is a number indicating the number of stars to generate, and the optional
parameter -c causes them to be assigned random colors (the default is for them
all to be white).

The stars are generated in a 1000 cubic unit box, which can of course be
scaled in a .wld file.  You can also load multiple starfields (or even
multiple copies of the same starfield, displaced and/or rotated) in a single
world file.  For example,

    object stars 10,10,10 0,0,0 -10000,-10000,-10000
    object stars 50,50,50 0,45,90 -20000,-10000,-30000

Since the stars are created in the positive x,y,z octant, the -10000 shift will
center the starfield around the origin.  The second starfield is shifted
somewhat away from the origin.

Keep in mind that each star takes up a fair amount of memory.

[---------------- Clip 'n' Save ---------------------------------------------]

/* Generate a star field as a .PLG file */

/* Written by Bernie Roehl, November 1992 */

#include <stdio.h>
#include <stdlib.h>

int starcount = 100;    /* number of stars to generate */
int colorflag = 0;      /* if non-zero, generate random star colors */

#define FSIZE 1000      /* size of the star field box */

#define STARCOLOR 15    /* stars are, by default, white */

void main(int argc, char *argv[])
    {
    int i;
    randomize();
    while (argc > 1) {
        if (!stricmp(argv[1], "-c")) colorflag = 1;
        else starcount = atoi(argv[1]);
        --argc;
        ++argv;
        }
    printf("starfield %d %d\n", starcount, starcount);
    for (i = 0; i < starcount; ++i)
       printf("%d %d %d\n", random(FSIZE), random(FSIZE), random(FSIZE));
    for (i = 0; i < starcount; ++i)
       printf("0x%04.4X 1 %d\n", colorflag ? (random(15) + 1) : STARCOLOR, i);
    }