[Coco] Colorful OS-9 Maze on CoCoTalk EOU B6 Preview 12/12

William Carlin whcarlinjr at gmail.com
Wed Dec 30 09:55:04 EST 2020


Greetings fellow CoCo Nuts and OS-9 / NitrOS-9 fans.

I was inspired by the person who is regularly on the CoCoTalk panel that
displays the OS-9 Maze program running on their CoCo 3.  The name of this
person is always too small and blurry to make out.  However, kudos to your
dedication to NitrOS-9 and your colorful display of the maze program.  This
program is typically black, white, and grey.  The panelist has changed the
colors to a dark blue maze, purple for the path color, and green for the
wrong path color.

I have the source for maze and was inspired to try and duplicate this color
scheme.  Being successful, I started to play around with other colors.  To
help me out I ran the COLOR3.BAS program from the Rainbow, January 1987
edition to look at all 64 colors in the color map at the same time.  I
quickly realized that these are not the colors displayed when selecting the
same palette numbers in NitrOS-9.  But that's a story for another time.

Once I played around with some various color options I decided that it
would be neat to just randomize the palette after each successful solving
of the maze.  Fortunately there is already a pseudo random function within
the program that makes this easy.  Here is a brief synopsis of how that
works.

First the random number generator is seeded in the while loop of the main
function using the C library time() function which returns the value of
time in seconds since 00:00:00 GMT, January 1, 1970 as a long integer.
Otherwise referred to as the epoch number.

rndseed = time();
srand ((unsigned)rndseed);

Then the random() function in the maze program accepts and returns an
unsigned integer number in the specified maximum range passed to the
function.  The number returned is between 0 and the number passed to the
function.

random ( num )
unsigned int num;
{
   return ( abs(rand (num) % num) );
}

I wanted to randomize the palette with as few lines of code as possible and
without using any new variables.  Also, while making sure that none of the
three pseudo random values were the same nor 0 or black.  For nostalgia I
kept the first solving of the maze in the default colors of white and dark
grey.  My code below is walled off by a #ifdef preprocessor declaration.  I
provided the entire while() loop so you know where to insert the new code.
At compile time you will have to specify '-dRNDPAL' in your makefile or at
the command line using the C compiler executive of your choice.  Enjoy.

while ( 1 )
        {
        rndseed = time();
        srand ((unsigned)rndseed);
        Clear ( outpath );
        FColor ( outpath, MAZEGROUND );
        initialize_maze();
        create_maze();
        solve_maze();
        tsleep ( ENDPAUSE );

#ifdef  RNDPAL                                    /*  Ranomize the palettes
 */
                              /*  Use some global variables already defined
 */
        start_x = random (62);
        Palette ( outpath, WRNGGROUND, start_x + 1 );
test1:  if ( (start_y = random (62)) == start_x )
            goto test1;
        Palette ( outpath, PATHGROUND, start_y + 1 );
test2:  if ( (end_x = random (62)) == start_x || end_x == start_y)
            goto test2;
        Palette ( outpath, MAZEGROUND, end_x + 1 );
#endif

        xoffset_count = ( xoffset_count + XINCR_OFFSET ) % XWOBBLE ;
        yoffset_count = ( yoffset_count + YINCR_OFFSET ) % YWOBBLE ;
        }
} /*  end of main() */

William Carlin, Jr.


More information about the Coco mailing list