Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

random_map.c

Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 
00004 /*
00005  *      random_map:  Make a random color map (write to stdout).
00006  *
00007  *      NOTE:  0 is black, 255 is white, by (my) convention!
00008  */
00009 
00010 make_colormap (unsigned char* red, unsigned char* green, unsigned char* blue)
00011 {
00012     int i;
00013 
00014     red[0] = green[0] = blue[0] = 0;
00015     for (i = 1; i < 255; i++) {
00016       red[i] = random() % 256;
00017       green[i] = random() % 256;
00018       blue[i] = random() % 256;
00019       while (red[i] + green[i] + blue[i] < 128) {
00020         red[i] *= 2;
00021         green[i] *= 2;
00022         blue[i] *= 2;
00023       }
00024     }
00025     red[255] = green[255] = blue[255] = 255;
00026 }
00027 
00028 main(int argc, char *argv[])
00029 {
00030     int i;
00031     unsigned char red[256], green[256], blue[256];
00032 
00033     if (argc <= 1)
00034       srand(42);
00035     else
00036       srand(atoi(argv[1]));
00037 
00038     make_colormap(red, green, blue);
00039 
00040     /* Format:  256 red bytes, 256 green, 256 blue. */
00041 
00042     for (i = 0; i < 256; i++) putchar(red[i]);
00043     for (i = 0; i < 256; i++) putchar(green[i]);
00044     for (i = 0; i < 256; i++) putchar(blue[i]);
00045 }

Generated at Sun Feb 24 09:57:12 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001