GRASS Programmer's Manual
6.4.3(2013)-r
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
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
}
lib
gis
color_rand.c
Generated on Thu Sep 26 2013 09:47:59 for GRASS Programmer's Manual by
1.8.4