• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

color_rand.c

Go to the documentation of this file.
00001 #include <time.h>               /*  For time()  */
00002 #include <stdio.h>              /*  For NULL */
00003 #include <stdlib.h>             /*  For rand() and srand() */
00004 #include <grass/gis.h>
00005 
00006 #define MAX_COLORS 1024
00007 #define DEVIATION 128
00008 
00009 
00022 int G_make_random_colors(struct Colors *colors, CELL min, CELL max)
00023 {
00024     unsigned char red, grn, blu;
00025     int count;
00026     CELL n;
00027 
00028     G_init_colors(colors);
00029     if (min > max)
00030         return -1;
00031 
00032     srand(time(NULL));
00033 
00034     count = MAX_COLORS - DEVIATION + rand() % DEVIATION;
00035     if (count > max - min + 1)
00036         count = max - min + 1;
00037 
00038     for (n = 1; n <= count; n++) {
00039         red = rand() & 0377;
00040         grn = rand() & 0377;
00041         blu = rand() & 0377;
00042         G_add_modular_color_rule(n, red, grn, blu, n, red, grn, blu, colors);
00043     }
00044     G_set_color_range(min, max, colors);
00045 
00046     return 1;
00047 }

Generated on Wed Oct 13 2010 12:09:29 for GRASS Programmer's Manual by  doxygen 1.7.1