GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
color_rand.c
Go to the documentation of this file.
1 #include <time.h> /* For time() */
2 #include <stdio.h> /* For NULL */
3 #include <stdlib.h> /* For rand() and srand() */
4 #include <grass/gis.h>
5 
6 #define MAX_COLORS 1024
7 #define DEVIATION 128
8 
9 
22 int G_make_random_colors(struct Colors *colors, CELL min, CELL max)
23 {
24  unsigned char red, grn, blu;
25  int count;
26  CELL n;
27 
28  G_init_colors(colors);
29  if (min > max)
30  return -1;
31 
32  srand(time(NULL));
33 
34  count = MAX_COLORS - DEVIATION + rand() % DEVIATION;
35  if (count > max - min + 1)
36  count = max - min + 1;
37 
38  for (n = 1; n <= count; n++) {
39  red = rand() & 0377;
40  grn = rand() & 0377;
41  blu = rand() & 0377;
42  G_add_modular_color_rule(n, red, grn, blu, n, red, grn, blu, colors);
43  }
44  G_set_color_range(min, max, colors);
45 
46  return 1;
47 }
int G_set_color_range(CELL min, CELL max, struct Colors *colors)
Definition: color_range.c:4
int G_add_modular_color_rule(CELL cat1, int r1, int g1, int b1, CELL cat2, int r2, int g2, int b2, struct Colors *colors)
Add modular color rule.
Definition: color_rule.c:310
#define min(x, y)
Definition: draw2.c:68
int count
#define DEVIATION
Definition: color_rand.c:7
#define MAX_COLORS
Definition: color_rand.c:6
#define max(x, y)
Definition: draw2.c:69
int G_make_random_colors(struct Colors *colors, CELL min, CELL max)
make random colors
Definition: color_rand.c:22
return NULL
Definition: dbfopen.c:1394
G_init_colors(colors)
int n
Definition: dataquad.c:291